JSON Undefined

dinesh91n
Tera Expert

Hi All,

I am working in a scoped application and getting this error log while trying to execute the JSON code, can anyone help me to fix this

java.lang.SecurityException: JSON undefined, maybe missing global qualifier

Caused by error in sys_trigger.9ef828964f5f9a00cbfa7bb28110c798 at line -1

Regards,

DInesh N

3 REPLIES 3

paramveer
Mega Guru

Hi Dinesh,



This error is due to undefined json string.


to avoid the exception you can use below check in your code :



if(json _ String!==undefined) {


//parse json here


}





Thanks,


Param


michal29
Mega Guru

Hello Dinesh,



You may want to take a look at :
JSON.stringify() - JavaScript | MDN



After stringify the text, JSON parsing should not throw errors.


Jace Benson
Mega Sage

Servicenow server side is using ES3, so somethings don't exist natively.   JSON is one of them.   So to include it now that scoping has been introduced.



E.g.


//Say event.parm1 is the stringified/encoded JSON payload;


gs.log('sys_trigger_9ef828964f5f9a00cbfa7bb28110c798 (string): ' + event.parm1);


var parser = new JSONParser();  


var obj = parser.parse(event.parm1);


gs.log('sys_trigger_9ef828964f5f9a00cbfa7bb28110c798 (obj.property): ' + obj.somePropertNameGoesHere);