- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2016 12:57 AM
Hello,
I have the following issue. I have a table with a field called "json_output". The user must filled it with valid json and then I want to process this data in a workflow script. So far, I've read about
var parser = new JSONParser();
var blades = parser.parse(current.json_output.toString());
But it seems it doesn't work in server-side scripts. When the script is executed it outputs the following message:
JSONParser undefined, maybe missing global qualifier
Can anybody tell me how to use JSON in workflow script?
Thanks,
Alexander
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-18-2016 02:15 AM
You can also use JSON method to decode your json_output. See below,
var json = new global.JSON();
var blades = new JSON().decode(current.json_output.toString());
gs.log('keyName1 - ' + blades.keyName1);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2016 01:34 AM
Just add a global keyword to access the JSONParser.
var parser = new global.JSONParser();
var blades = parser.parse(current.json_output.toString());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2016 03:38 AM
That solved the UI error message, but led to another. According to ServiceNow system logs, the variable parser is undefined - Caught exception in InterpretedScript <refname>: org.mozilla.javascript.JavaScriptException: org.mozilla.javascript.WrappedException: WrappedException of The undefined value has no properties.
If i write the gs.addInfoMessage(new global.JSONParser()); seems everything is ok because it prints [Object], but if i try to call anything from that, it gives me error in the system logs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2016 10:28 AM
I attempted this from both background script and business rule, and it worked okay for me. To do a little testing, can you try something like the following?
var JSONObj = '{"name":"Alexander","lastname":"Yordanov"}';
var parser = new JSONParser();
var blades = parser.parse(JSONObj);
gs.print(blades.name);
//Should get 'Alexander'
This should be a simple proof of concept, and will help in determining what the issue is.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2016 02:52 PM
Hi Alexander,
The script include JSONParser is not client-callable, i.e. you can only use it on the server side... A few questions:
- You mentioned a UI error message, where are you trying to use it?
- Also, what version SNOW are you using?
- And maybe copy in your latest script(s) that are kicking back an error.
Thanks,
-Brian