0
<script runat=server>
Platform.Load("Core","1.1.1");
  try{

  var newpay = Stringify({"failedRecords":[
    {
      "customerId":"qXTjiIDaG",
      "productCode":"1",
      "journeyName":"1",
      "journeyStage":"1",
      "providerError":[
        {
          "code":"COP_SFMCOFFER_05",
          "detail":"Customer 312916483 is not existing"
        }
      ]
    },
    {
      "customerId":"XQtEDUCHz",
      "productCode":"1",
      "journeyName":"ABC",
      "journeyStage":"PQR",
      "providerError":[
        {
          "code":"COPOFFER_02",
          "detail":"Main campaign offer is unavailable for SMS and EMAIL channels"
        }
      ]
    },
    {
      "customerId":"ocFD5pWQZ",
      "productCode":"1",
      "journeyName":"ABC",
      "journeyStage":"PQR",
      "providerError":[
        {
          "code":"COP_SFMCOFFER_02",
          "detail":"Main campaign offer is unavailable for SMS and EMAIL channels"
        }
      ]
    }
  ],
  "successfulRecords":[
    {
      "offerType":"001daLE",
      "campaignId":"QUERYSITUATIONRULE",
      "waveId":"43764UJQAG",
      "waveDescription":"TESTING WITH QUEY SITUATION",
      "customerId":"BSUP1p2JX",
      "journeyName":"ABC",
      "journeyStage":"PQR",
      "offerStartDate":"2019-11-28",
      "offerExpiryDate":"2020-03-07",
      "offerPriority":"1",
      "offerStatus":"C",
      "productCode":"0ad",
      "productDescription":"paya",
      "channel":[
        "SMS"
      ],
           "userFields": [
        {
          "userFieldsKey": "FER_PRIORITY",
          "userFieldsValue": 1
        },
        {
          "userFieldsKey": "ARD_TYPE",
          "userFieldsValue": 115
        }

      ],
      "offerid": "HM6T7jc9Fj2G9tx",
      "smsTemplateFields": [
        {
          "templateFieldKey": "smsTxnParam1",
          "templateFieldValue": "ABC"
        },
        {
          "templateFieldKey": "smsTxnParam2",
          "templateFieldValue": "ABC"
        },

        {
          "templateFieldKey": "smsTxnParam3",
          "templateFieldValue": "ABC"
        }

      ],
      "emailTemplateFields": [
        {
          "templateFieldKey": "emailTxnParam1",
          "templateFieldValue": "ABC"
        },
     {
          "templateFieldKey": "emailTxnParam2",
          "templateFieldValue": "DEFGHJ"
        },
     {
          "templateFieldKey": "emailTxnParam3",
          "templateFieldValue": "DSFSAFFSH"
        }
      ]
    }
  ]});

     var test = Platform.Function.ParseJSON(newpay);
var sucessfullrecords = test.successfulRecords;
var another = sucessfullrecords[0];
Write(another.offerType);



                  </script>

  <script runat="server">
  }catch(e){
    Write(Stringify(e));
  }
</script>

***able to Print offer type but now issue is " userFields" which is an array, need help to parse this and wanted to print "userFieldsValue".

0

In order to access the userFieldsValue of every entry in that array you need to loop through it. So in your code (for the first successful record, that you have written to the "another" variable) it works like this:

for (var i=0; i<another.userFields.length; i++) {
    Write(another.userFields[i].userFieldsValue);
}

If you like to output these values for every successful record, it looks like this:

for (var i=0; i<test.successfulRecords.length; i++) {
    for (var j=0; j<test.successfulRecords[i].userFields.length; j++) {
        Write(test.successfulRecords[i].userFields[j].userFieldsValue);
    }
}

Note: If the JSON format isn't stable, you should also add checks if the property you like to access is defined first.

| improve this answer | |

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