Expand my Community achievements bar.

SOLVED

Personalization Bloc Issue

Avatar

Level 2

Hello,

 

I am setting a personalization bloc to encrypt and decrypt as the following:

<%
var IV_SIZE = 8; // Replace with the desired size

String.prototype.hexEncode = function () {
var result = '';
for (var i=0; i<this.length; i++) {
result += this.charCodeAt(i).toString(16);
}
return result;
}

function generateRandomString(size) {
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var result = '';

for (var i = 0; i < size; i++) {
var randomIndex = Math.floor(Math.random() * characters.length);
result += characters.charAt(randomIndex);
}

return result;
}

//Adobe Campaign JS CODE to crypt 'Hello my friend' with 'CF12D5998AE799C6' key :
var key = '11be5d01690fb6f9dfb99c79fXXXXX';
var mBuffer = new MemoryBuffer(); mBuffer.fromString(key);
var b64Key = mBuffer.toBase64();

var recipientMongoId = '',
recipientSalt = '',
deliveryCode = '',
gridCode = '',
gridVersion = '',
parentCartId = '',
delivery = '',
recipient = '',
variables = '',
randomString = '',
ivString = '',
IV_SIZE = '',
dateX = '';

if (typeof rtEvent != 'undefined') {
// Get given encryptedString, decrypt it and modify its value
var encryptedString = rtEvent.ctx.@encryptedData.toString();
var iv = ivString.slice(0, IV_SIZE).hexEncode();
encryptedString = encryptedString.slice(IV_SIZE);
var cryptkey = CryptoJS.enc.Utf8.parse('11be5d01690fb6f9dfb99cXXXXX'); //The key used, in text format
crypted = "toEncrypt"; //encrypted data
var _decrypted = CryptoJS.AES.decrypt(crypted, cryptkey, {
iv: CryptoJS.enc.Hex.parse('00000000000000000000000000000000'),
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
});

logInfo("-- " + decrypt.toString(CryptoJS.enc.Utf8) + " --")

recipientMongoId = _decrypted.lid;
recipientSalt = _decrypted.salt;
gridCode = variables.gridCode;
gridVersion = variables.gridVersion;
deliveryCode = variables.deliveryCode;

} else {
// Get deliveryCode from delivery template
deliveryCode = delivery.deliveryCode;

// Get lead mongoId & salt
recipientMongoId = recipient.mongoId;
recipientSalt = recipient.salt;

// For loyalty products, the gridCode has been moved into gridVersion and the gridCode is the lead score
gridVersion = variables.gridVersion;
gridCode = recipient.scoring;

if (variables.gridCode && variables.gridCode != '') {
gridCode = variables.gridCode;
}

// For AC/PM mailing: Concatenate gridVersion from previous cart (MD) with an eventually existing gridVersion stored into the delivery template
// Get also cart mongoId from previous cart (MD) in order to link carts for stats
// Be careful, alias must be "orderHistory" in enrichment
try {
// For normal strat, gridVersion stored in targetData (data stored in working tables of workflows)
if (targetData.gridVersion && targetData.gridVersion != '') {
gridVersion = targetData.gridVersion;
}
if (targetData.gridCode && targetData.gridCode != '') {
gridCode = targetData.gridCode;
}
if (targetData.dateX && targetData.dateX != '') {
dateX = targetData.dateX;
}

if (targetData.orderHistory) {
if (targetData.orderHistory.gridVersion && targetData.orderHistory.gridVersion != '') {
gridVersion = targetData.orderHistory.gridVersion + gridVersion;
}
if (targetData.orderHistory.mongoOrderId && targetData.orderHistory.mongoOrderId != '') {
parentCartId = targetData.orderHistory.mongoOrderId;
}
if (targetData.orderHistory.gridCode && targetData.orderHistory.gridCode != '') {
gridCode = targetData.orderHistory.gridCode;
}
}
}
catch (e) {
}
}

//var ivString = randomString(IV_SIZE)
var iv = ivString.hexEncode();//'11be5d01690fb6f9';

var data = {
lid: recipientMongoId,
salt: recipientSalt,
data: {
channel: {
"name" : "EMAIL",
"source" : {
"type" : "ADOBE_CAMPAIGN",
"detail" : variables.detail
}
},
dropCode: deliveryCode,
gridCode: gridCode,
gridVersion: gridVersion
}
};

if (parentCartId && parentCartId != '') data.data.parentCartId = parentCartId;
if (dateX && dateX != '') data.data.date = dateX;

var toEncrypt = JSON.stringify(data);

var encrypted = '?k=' + ivString + cryptString(toEncrypt,key,'CBC',iv).replace(/\//g,'_').replace(/\+/g,'-').replace(/=+$/, '');

%>

 

When I try to sent an email I get an error that recipient  and recipient.OrderHistory are undefined not defined. 

 

assiba_johnson_0-1704376196774.png

 

 

Anyone can help here? What I am doing wrong?

 

Thanks in advance. 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Level 2

Hi @SatheeskannaK,

 

I found a solution from my end by using cryptoJS.DES encryption method. We can archive this case.

 

Thanks,

Assiba

View solution in original post

5 Replies

Avatar

Community Advisor

@assiba_johnson, Are you using adobe campaign standard?

Thanks, Sathees

Avatar

Community Advisor

Hello @assiba_johnson 

 

Would you mind checking if you have used recipient.OrderHistory in any other part of your delivery, perhaps in the text version?

The fastest way to check is to open your delivery in xml format like below and check for recipient.OrderHistory 

 

Amine_Abedour_0-1704476031900.png

Br,

Amine 

 

Avatar

Level 2

@amine, many thanks for your reply. Actually you could not find one.

 

assiba_johnson_0-1704480477738.png

 

Avatar

Correct answer by
Level 2

Hi @SatheeskannaK,

 

I found a solution from my end by using cryptoJS.DES encryption method. We can archive this case.

 

Thanks,

Assiba