3

I have a script that is retrieving rows from a data extension and then looping through said rows.

The data extension is coming from a SF report so I can't edit the column names without copying it to another DE using SQL (which feels roundabout/clunky).

My issue is that I have a column with a space but bracket notation isn't working.

Here's the snippet of code that is causing the script to fail:

 var Record_ID = "";

 // get list of records
  var de = DataExtension.Init("Data_Extension_Name");
  var data = de.Rows.Retrieve();

  // Loop through the result set captured in the 'data' object
  for ( i in data )  {

Record_ID = data[i]["Record: ID"];
          if (Record_ID !== "") {

Record_ID = data[i]["Record: ID"]; is the offending line.

If I attempt the same script but use a field with no spaces or brackets (EX: data[i].Status) then it's fine.

I have tried the below combos and nothing has worked:

 Record_ID = data[i]["Record: ID"];

 Record_ID = data[i].[Record: ID];

 Record_ID = data[i]['Record: ID'];

Usually brackets work for fields with spaces but the SSJS doesn't seem to like brackets following data[i].

I even made a dummy variable and tried using that.

var Record_ID = "";
 var test = "Record: ID";

     // get list of records
      var de = DataExtension.Init("Data_Extension_Name");
      var data = de.Rows.Retrieve();

      // Loop through the result set captured in the 'data' object
      for ( i in data )  {

    Record_ID = data[i].test;
              if (Record_ID !== "") {

Will I really have to use SQL to rename the fields and copy all the data to a second DE??

1

I tried with data[i]['Record: ID'] and it's work without any issue.

<script runat=server>
  Platform.Load("Core","1");
    var Record_ID = "";
    var de = DataExtension.Init("DataExtension External Key");
    var data = de.Rows.Retrieve();

      for ( i in data ){
      Write(data[i]['Record: ID']);
      }
</script>   
  • Thank you fr the feedback! It didn't seem to execute even with data[i]['Record: ID'] for me so I ended up using a SQL interaction to just rename the field names. – R.Garton Jun 16 '17 at 15:45

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.