- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2019 02:48 PM
I'm new to ServiceNow and trying to build a "receiver" for a webhook fired by our service (Office365Mon.Com). I started with a Scripted REST API, and it seems to work to the extent that I'm able to send our JSON payload over to the application and it is received. The problem is, I've spent two days trying to figure out how to parse the JSON that is received. Here's a simplified sample JSON I'm using to test this:
{"SubscriptionId": "79e90671-1234-1234-1234-cf2b0fa6743c","CompanyName": "Office365Mon.Com","WebhookNotificationType": 0}
I've tried working with both the request.body.data and request.body.dataString objects. My first assumption was that request.data.body would be able to give me something like this:
var myData = request.body.data;
var id = myData.SubscriptionId //says it is undefined
So then I tried all sorts of parsing options. For simplicity's sake I've tried these two:
var reqData = request.body.dataString;
//var p = new JSONParser();
//var jData = p.parse(reqData);
//var p = new JSON();
//var jData = p.decode(reqData);
Both of these throw exceptions when trying to use. I've added script includes for both JSON and JSONParser. The JSON error is "ReferenceError: "SNC" is not defined. I've looked and I can't find any global include for "SNC". The JSONParser error is ConversionError: The undefined value has no properties.
I've been at this for two days straight and have tried all the different ways I know that work in regular client javascript, and none of them seem to work in this ServiceNow app. What am I missing?
Thanks,
Steve
Solved! Go to Solution.
- Labels:
-
Integrations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2019 02:30 PM
As often happens, after I posted this and struggling for a couple of days, I found the answer about 15 minutes later. Apparently one needs to prefix the JSON class with "global" in order for it to work. For example, this is what works:
var jData = new global.JSON().decode(reqData);
The answer came buried in a four year old blog post found here (so credit to it): http://www.cavucode.com/blog/2015/3/29/fujiforty-what-happened-to-jsonparser
Would really be super awesome if little nuggets like this made it into the ServiceNow documentation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2019 02:30 PM
As often happens, after I posted this and struggling for a couple of days, I found the answer about 15 minutes later. Apparently one needs to prefix the JSON class with "global" in order for it to work. For example, this is what works:
var jData = new global.JSON().decode(reqData);
The answer came buried in a four year old blog post found here (so credit to it): http://www.cavucode.com/blog/2015/3/29/fujiforty-what-happened-to-jsonparser
Would really be super awesome if little nuggets like this made it into the ServiceNow documentation.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2019 02:41 PM
Hi Steve,
Just an FYI you can also simply use javascript native JSON.parse() like so:
var x = '{"SubscriptionId": "79e90671-1234-1234-1234-cf2b0fa6743c","CompanyName": "Office365Mon.Com","WebhookNotificationType": 0}';
var obj = JSON.parse(x);
You can see the documentation here.
Cheers.
--David