2

I am trying to loop through all rows of a data extension and update the name of each record. I created an SSJS script activity to run the below code and it is not erroring out, but it is not updating my data extension either.

I have almost the exact same syntax in another script activity working just fine, but no luck with this one. Also, if I take the code out of the FOR loop and remove the subKey and hard code in a specific value then it will work, but I need that additional functionality to solve for the problem at hand. How do I fix it?

<script runat="server">
  Platform.Load('core', '1');

  var testDE = DataExtension.Init('Test12345');
  var testDEData = testDE.Rows.Retrieve();

  for (var i = 0; i < testDEData.length; i++) {
      var subKey = testDEData[i].SubscriberKey;

      var processing = testDE.Rows.Update({Name:'Bob'}, ['SubscriberKey'], [subKey]);
  }
</script>
  • 1
    Try and initialise the subKey variable at the top of your page var subKey;, then in your for loop do the following subKey = testDEData[i].SubscriberKey;. – thechrishaddad Feb 28 '19 at 0:13
  • 1
    Have you verified that subKey is returning a value? It sounds like with the var, there is no match, which is why it is not updating. – Gortonington Feb 28 '19 at 13:59
1

This code actually does work as written, the issue I was having was due to using the data extension's name in the Init() line, rather than the external key. Thanks for the suggestions!

0

Try using this code on a landing page to debug the problem. Create a new landing page and put the code in an HTML bloc.

Save and click Schedule/Publish button (this will execute your SSJS code). You will get a preview of the page. If your code contains errors, it will keep spinning, otherwise you will get the subKey values on the screen.

<script runat="server">
  Platform.Load('core', '1');

  var testDE = DataExtension.Init('Test12345');
  var testDEData = testDE.Rows.Retrieve();

  for (var i = 0; i < testDEData.length; i++) {
      var subKey = testDEData[i].SubscriberKey;

      // prints the subKey's value on the screen
      Write(subKey + ' / ');

      var processing = testDE.Rows.Update({Name:'Bob'}, ['SubscriberKey'], [subKey]);
  }
</script>

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.