Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

What is the alternate for JSONParser() API in scoped app?

sasi
Tera Contributor

Hi All, 

 

I came across issue with parsing i have a JOSN format which need to be parsed. As new JSONParser() API deprecated in global cannot be used in scoped applications.can you suggest what is the alternate for this?

 

        var SampleArray = {
             "arr": [{
                 'number': 'CM0213631'
             }]
       };
 
        var a = JSON.stringify(SampleArray);
        var parser = JSON.parse(a);
        var parsed = parser.parse(a);
for (var i = 0; i < SampleArray.length; i++) {
var inv = new GlideRecord('table_name');
inv.addQuery('number', SampleArray.arr[i].number);
inv.query();
while (inv.next()) {
gs.info("Testingscheduledjob2");
}
1 ACCEPTED SOLUTION

SANDEEP28
Mega Sage

@sasi You can JSON API methods using global keyword in scoped app. Refer below document

 

https://docs.servicenow.com/en-US/bundle/tokyo-api-reference/page/app-store/dev_portal/API_reference...

 

Use below corrected code

 

var SampleArray = {
             "arr": [{
                 'number': 'CM0213631'
             }]
       };
 
var jsonObject = global.JSON.stringify(SampleArray);
var parser = global.JSON.parse(jsonObject);
var arrayObject = parser.arr;
for (var i = 0; i < arrayObject.length; i++) {
var arrayElementObject = global.JSON.stringify(arrayObject[i]);
var arrayElement =  global.JSON.parse(arrayElementObject);
var grObject = new GlideRecord('table_name');
grObject.addQuery('number', arrayElement.number);
grObject.query();
while (grObject.next()) {
gs.info("Testingscheduledjob2 ");
}
}

 

If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!

View solution in original post

2 REPLIES 2

SANDEEP28
Mega Sage

@sasi You can JSON API methods using global keyword in scoped app. Refer below document

 

https://docs.servicenow.com/en-US/bundle/tokyo-api-reference/page/app-store/dev_portal/API_reference...

 

Use below corrected code

 

var SampleArray = {
             "arr": [{
                 'number': 'CM0213631'
             }]
       };
 
var jsonObject = global.JSON.stringify(SampleArray);
var parser = global.JSON.parse(jsonObject);
var arrayObject = parser.arr;
for (var i = 0; i < arrayObject.length; i++) {
var arrayElementObject = global.JSON.stringify(arrayObject[i]);
var arrayElement =  global.JSON.parse(arrayElementObject);
var grObject = new GlideRecord('table_name');
grObject.addQuery('number', arrayElement.number);
grObject.query();
while (grObject.next()) {
gs.info("Testingscheduledjob2 ");
}
}

 

If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!

sasi
Tera Contributor

Thank you so much..it's working as expected