0

i'm trying to get a specific field in a ssjs request, but the Platform.Function.ParseJSON returns null with the Stringify. Whe i try without the 'Stringify' returns 500 erros

but the 'Rows.Retrieve' works, the 'Write("The Value " + Stringify(data));' returns all the rows in DE.

       <script runat="server">
Platform.Load("core", "1.1.1");
    
    var stagingDE = DataExtension.Init("...-E2D8-4864-99CF-69CBCCA1F950");
    var data = stagingDE.Rows.Retrieve();
   if (typeof(data) == 'object' && data.length > 0) {
     var obj = Platform.Function.ParseJSON(Stringify(data));
     var val = obj.DataXML; 
     Write("The Value " + Stringify(val));
     Write("The Value " + Stringify(data));

    } else {
      Write("No Rows Found");
    }
</script>
1
  • You shouldn't need to parse the response. It's already JSON. Commented Dec 28, 2021 at 17:30

1 Answer 1

2

I'd use a try/catch to trap any errors. I think you're probably referring to DataXML improperly. I'd suggest pasting the results into jsonpathfinder.com to find the correct reference to output it.

<script runat="server" language="JavaScript">

Platform.Load("core", "1");
var debug = true;

try {

  var stagingDE = DataExtension.Init("...-E2D8-4864-99CF-69CBCCA1F950");
  var data = stagingDE.Rows.Retrieve();

  if (typeof(data) == 'object' && data.length > 0) {

    if (debug) {
      Write("<br>data: " + Stringify(data));
    }

    // loop through results here

  } else {
    Write("<br>No Rows Found");
  }

} catch (e) {

 if (debug) {
  Write("<br>e: " + Stringify(e));
 }

}
</script>
3
  • Thanks, Adam. But the DataXML it's ok. This is the JSON response in Rows.Retrieve My goal it's dsplay the: DataXML [{"Invoice_Number__c":"", "Base64Encode":"", "AccountContract":"", "DataXML":"", "Name":"", "InvoiceReference__c":"", "EmissionDate__c":"", "pURL":"", "Id":"", "BP_Id":"", "DocumentNumber__c":"", "InvoiceAccess__c":""}]
    – João
    Commented Dec 28, 2021 at 18:45
  • 1
    Then after the conditional you can refer to DataXML with: data[0].DataXML. You can't display XML directly, since your browser will try to render it. You can do something like this: Write("DataXML: ", data[0].DataXML.replace("<","&lt;")) Commented Dec 28, 2021 at 19:57
  • Thanks @Adam :D. With data[0].DataXML now i have the display value.
    – João
    Commented Dec 28, 2021 at 20:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .