1

I have the following script that returns the array as expected. When I go to add the "Rows.Add" aspect, I get a 500 error. I am testing the script on a cloudpage with plans to move it to an automation. The code works without the Rows.Add. The data is a large array formatted as [{"ID":1,"Type":#,"Name":"","APR":#,"Category":"None","IsActive":true},...]. The array is around 50 elements and the data extension lines up 1 to 1 with field names. My manual test payload also adds correctly.

<script runat="server" language="javascript">
Platform.Load("Core","1.1");
...
var response = HTTP.Get(url, headerNames, headerValues);
arr = response.Content;
var de = DataExtension.Init(EXTERNALKEY);

//var addedRowCount = de.Rows.Add(arr);

Write("Rows added: " + addedRowCount ); 
</script>
5
  • Can you wrap the de.Rows.Add() function in a try catch? try { ...your code } catch(e) { Write(Stringify(e)) } and this should give you a write out on the page for what the error is. But honestly I get the feeling that your array is coming in as a string and not an array so might need to do ParseJSON() on it to turn it to the correct data type. Commented Sep 7, 2021 at 16:50
  • Hi, I tried both of these with no luck. The error returned just says 'error adding to data extension'. I tried to loop and just send the first line item but again, no luck (I realize this was bad practice but worth a shot). When I output the array to a cloudpage, It is in an array format. The single line outputted 'System.Collections.Generic.Dictionary`2[System.String,System.Object]'. I formatted my manual array the exact same as the returned array and that worked correctly. Commented Sep 7, 2021 at 23:34
  • Try Stringifying the returned array and writing it to CP. Just to make sure it is returning as expected Commented Sep 7, 2021 at 23:53
  • 1
    I appreciate your help. I realized even though it looked like an array, it was actually a string. You were correct originally and I called ParseJSON incorrectly. Thank you! Commented Sep 8, 2021 at 17:06
  • Awesome @TariqMcleod! Glad you figured it out. Great work! Commented Sep 8, 2021 at 20:38

0

You must log in to answer this question.

Browse other questions tagged .