0

I have a SSJS to be used in rest api calls. It will be an scheduled call thus this is an script activity. The script automation returns a success but I do not see any changes, it should write to DE if there is any error. Any idea why it does not write? code below.

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

var log = DataExtension.Init("3C75861E-6F23-43D2-BA36-7DCE4111464E");

try{

    var leads = DataExtension.Init("6D129A34-522B-4E0C-88CC-D1EC41994E25"); 
    var filter = {Property:"accountNumber", SimpleOperator:"isNull"}; 
    var data = leads.Rows.Retrieve(filter);
    var secKey = "xxxxx";
    var chCode = "48";
} catch (e) {

      e = Stringify(e).replace(/[\n\r]/g, '');
      log.Rows.Add({Message: "error: " + e});

}

for (var i = 0 ; i < data.length ; i ++) {

    try {
    var url = 'xxxxxx';
    var contentType = 'application/json';
    var payload = '{';
        payload += '"securityRequest":{';
        payload += '"securityKey": "'+secKey+'",';
        payload += '"channelCode": "'+chCode+'",';
        payload += '},';
        payload += '"parameter":{';
        payload += '"firstName": "'+data["firstName"]+'",';
        payload += '"lastName": "'+data["lastName"]+'",';
        payload += '"countryId": "'+data["countryId"]+'",';
        payload += '"accountStatus": "'+data["accountStatus"]+'",';
        payload += '"createSource": "'+data["createSource"]+'",';
        payload += '"storeCode": "'+data["storeCode"]+'",';
        payload += '"communicationCountryId": "'+data["communicationCountryId"]+'",';
        payload += '"emailAddress": "'+data["emailAddress"]+'",';
        payload += '"DOB": "'+data["DOB"]+'",';
        payload += '"emailOption": "'+data["emailOption"]+'",';
        payload += '}';


      var result = HTTP.Post(url, contentType, payload, null);
      result = Stringify(result).replace(/[\n\r]/g, '');
      log.Rows.Add({Message: "result: " + result});

    } catch (e) {

      e = Stringify(e).replace(/[\n\r]/g, '');
      log.Rows.Add({Message: "error: " + e});

    }

}
  • 1
    Are you sure your call is returning results or even running? The issue could be that the data var is empty, so the for loop is not running at all or the result var comes back empty due to incorrect auth. I say this because the data, secKey and chCode only seem to be in scope for the duration of the first try block. You will need to return these vars to utilize them outside that environment. – Gortonington Jun 11 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.