0

I am trying to split string variable in ssjs script but my automation always turns into error below is my code to split the string:

  var str = '<CreatedDate>2018-10-24T04:31:00</CreatedDate>';  
           +'<ModifiedDate>2018-10-24T04:31:00</ModifiedDate>';
           +'<ID>3844854</ID>';
           +'<ObjectID xsi:nil=\"true\" />';
           +'<Status>Active</Status>';
           +'<SubscriberKey>00320000005ccPqAAI</SubscriberKey>';

  var subscriberKey1 = str.split("<SubscriberKey>")[1];
  var subscriberKey = subscriberKey1.split("</SubscriberKey>")[0];
  var modifiedDate1 = str.split("<ModifiedDate>")[1];
  var modifiedDate = modifiedDate1.split("</ModifiedDate>")[0];
  var status1 = str.split("<Status>")[1];
  var status = status1.split("</Status>")[0];
  var createdDate1 = str.split("<CreatedDate>")[1];     
  var createdDate = createdDate1.split("</CreatedDate>")[0];

This script gives error and I am unable to find cause because there is no other way of splitting string in SSJS script. Is it the correct way of splitting string? If NO then please tell me the other way and if yes then why its not working?

Waiting for reply

0

split is available, and is the right way to split a string. You have syntax errors in your code. If you are concatenating a string over multiple lines, don't end each line with a semicolon.

var a = "qwe"
      + "rty";
0

The data format you're showing is called XML (except you need a root node).

What you're really asking is "How do I parse XML strings in Marketing Cloud's Server Side JavaScript". That question has been answered at the following Salesforce StackExchange link. You'll want to surround your string with a root node first.

Parse XML in Server Side Javascript

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.