- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2014 12:36 PM
I have a Business Rule with a custom script. The task of this script is to get the JSON of a Change Request by calling a REST message
For this REST message call, the sys_id is the input parameter.
How can I get the sys_id for the current Change Request on which the Business rule is triggered?
var req = new RESTMessage('Get_SN_JSON', 'get'); //this is a pre-defined REST message in the system
req.setStringParameter('sysID', current.sys_id); //here the current change_request's sys_id should be passed
current.sys_id, getUniqueValue(), current.variables.sys_id, getSystemID() --- all these return 'undefined'.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2014 01:15 PM
You could try using the following:
var jsonString = new JSON().encode(resJson);
You can't use JSON.stringify in a business rule since I believe that's only a browser-side capability. Thankfully SN has a lot of these capabilities built-in server-side, albeit under slightly different names.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2014 12:46 PM
Have you tried the toString method?
current.sys_id.toString()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2014 01:07 PM
using "toString()" helped me see the correct sys_id. Thank you!
But when this value is passed to the REST message it shows me [object Object] as response instead of the JSON
var req = new RESTMessage('Get SN JSON', 'get');
req.setStringParameter('sysID', current.sys_id.toString());
myapp.log("sys id: "+ current.sys_id.toString()); //correct sys_id shown here
var resJson = req.execute();
myapp.log("Response: "+ resJson.toString()); //Response: [object Object] in the logs
With or Without toString() Response is same. I tried JSON.Stringify() as well. Result is 'undefined'. Any ideas on what is going wrong?
Once I get the correct JSON, it has to be passed as input to another REST message in the script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2014 01:15 PM
You could try using the following:
var jsonString = new JSON().encode(resJson);
You can't use JSON.stringify in a business rule since I believe that's only a browser-side capability. Thankfully SN has a lot of these capabilities built-in server-side, albeit under slightly different names.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2014 01:31 PM
Thank you! That helped me see the 'Response' content.
Response: {"endpoint":"https://myserver.service-now.com/api/now/table/change_request/8dc7b2c30f27e10032c5778ce1050e09","errorCode":"","errorMessage":"","parameters":"sysparm_display_value=true","response":{}}
However, I was expecting to see the actual JSON of the Change Request. When I place the endpoint from this response in the browser, it shows me the JSON correctly indicating that the web service itself is functioning properly.
How can I get the endpoint response JSON instead of what I see above?