0

I want to pull a data extension DE1 where it has two columns I used wsproxy to copy these column values to another data extension where one of the two column is encrypted and another column needs to fetched and added as it is .

The issue is SSJs is not updating the second column value as the loop for this Wsproxy works in way that it takes col1 name and col2 value. It moves to another column and takes the header with its value

Tried different if conditions still its not updating col2 values in the DE2

<script runat="server">

Platform.Load("core", "1.1.1");

var records = retrieveAllRecords("de1");

Write(Stringify(records));
  Write(records[1].ServiceKey);
Write(records[1].Alias);
 
function retrieveFieldNames(name) {

    var attr = DataExtension.Retrieve({ Property: "Name", SimpleOperator: "equals", Value: name });

    var de = DataExtension.Init(attr[1].CustomerKey);

    var fields = de.Fields.Retrieve();

    fields.sort(function (a, b) { return (a.Ordinal > b.Ordinal) ? 2 : -2 });

    var out = [];

    for (k in fields) {
        out = out.concat(fields[k].Name);
    }

    return out;

}

function retrieveAllRecords(name) {

    var prox = new Script.Util.WSProxy();

    var cols = retrieveFieldNames(name);

    var config = {
        name: name,
        cols: cols,
    }

    var records = [],
        moreData = true,
        reqID = data = null;

    while (moreData) {

        moreData = false;

        if (reqID == null) {
            data = prox.retrieve("DataExtensionObject[" + config.name + "]", config.cols);
        } else {
            data = prox.getNextBatch("DataExtensionObject[" + config.name + "]", reqID);
        }

        if (data != null) {
            moreData = data.HasMoreRows;
            reqID = data.RequestID;
            for (var i = 0; i < data.Results.length; i++) {
                var result_list = data.Results[i].Properties;
                var obj = {};
                for (k in result_list) {
                    var key = result_list[k].Name;
                    var val = result_list[k].Value;
                   //var encodedStr = Platform.Function.Base64Encode(val); // encoding as argument may include ' or " chars

   var TestDE = DataExtension.Init("De2");
   
                try{
        
    var amp = '%' + "%[ Output(Concat(EncryptSymmetric('" + val + "', 'AES',";
         amp += "'enkey_password', @null,";
         amp += "'enkey_salt', @null,";
         amp += "'enkey_vector', @null)))";
         amp += ']%' + '%';
         
         if(key == "ServiceKey"){
          var val = Platform.Function.TreatAsContent(amp);
           var result = TestDE.Rows.Add({"ServiceKey":val}); 
         }
         if(key != "ServiceKey")/***it is not working** /
       {
            var result = TestDE.Rows.Add({"Alias":val}); /* the value is not added into the data extension*/
       }
                  }catch(ex){
               Write("An error has occurred: " + Stringify(ex));
        Write("   deObj: " + Stringify(deObj));
        Variable.SetValue("@Result", Stringify(ex));
                  }
                  
                    
                    if (key.indexOf("_") != 0) obj[key] = val;
                    
                                              
                }
                records.push(obj);
            }
        }
    }
    return records;
}
</script>

Little guidance would help me !

1 Answer 1

0

It seems like you're setting the variable val only if key == "ServiceKey". I suppose if you move that declaration up a level it would work?

var val = Platform.Function.TreatAsContent(amp);
if (key == "ServiceKey") {
  var result = TestDE.Rows.Add({ "ServiceKey": val });
}
if (key != "ServiceKey")/***it is not working**/ {
  var result = TestDE.Rows.Add({ "Alias": val }); /* the value is not added into the data extension*/
}
1
  • I have tried placing If condition in different lines but still i was getting only the value for servicekey not for the alias ,also i want to encryt only the service key and want to keep alias as it is but in turn both alias and service key is getting encrypted which i dont want
    – Prash
    May 19, 2023 at 11:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .