- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2020 08:01 AM
Hi , I m working on an integration in which third party tool is creating record in servicenow instance. Hence we are reading the values in scripted rest and doing the insert. The requestData has some key value pair in nested json format . e.g below. How do I fetch the values of requested_for and requester_id separately so I could insert them to their respective columns in the record? Please advise.
json body
"number":"SCTASK0010157",
"description":"test",
"user_info":
{"requested_for":"sameer s", "requester_id" :"001"}
scripted rest
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var requestBody = request.body;
var requestData = requestBody.data;
var taskNumber = requestData .number;
var desc = requestData.description;
var user_information = requestData.user_info;
var n = user_information.requested_for; // not working
var m = requestData["user_information"]["requester_id"]; // not working
})(request, response);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2020 12:35 PM
I lost correct on this one. Ankur's initial response had user_info key missing in the script 😉
- Pradeep Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2020 08:25 AM
Hi,
sample script below; it will work; forgot to add the user_info key
var reqbody = request.body.dataString;
var parser = new global.JSON();
var parsedData = parser.decode(reqbody);
var requestedFor = parsedData.user_info.requested_for;
var requester_id = parsedData.user_info.requester_id;
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2020 12:34 PM
I lost correct on this one. Ankur's initial response had user_info key missing in the script 😉
- Pradeep Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2021 07:41 AM
Hi Ankur,
I'm also having the same scenario, Here i can get description value but not able to get the (value":"euhubzpa102") any help on this one.
{"schemaId":"AzureMonitorMetricAlert","data":{"version":"2.0","properties":null,"status":"Activated","context":{"timestamp":"2021-10-12T09:25:21.7021523Z","id":"/subscriptions/933c2f10-9eff-49d0-a490-60ce1c3a0c72/resourceGroups/EU-HUB-PRD-AUT-RG001/providers/microsoft.insights/metricAlerts/EU-MON-LINUX-DISK-WARNING-ALERT01","name":"EU-MON-LINUX-DISK-WARNING-ALERT01","description":"This is a warning alerts describes that one of the linux server instance used space is more than 90%.","conditionType":"SingleResourceMultipleMetricCriteria","severity":"3","condition":{"windowSize":"PT30M","allOf":[{"metricName":"Average_% Used Space","metricNamespace":"Microsoft.OperationalInsights/workspaces","operator":"GreaterThan","threshold":"90","timeAggregation":"Average","dimensions":[{"name":"Computer","value":"euhubzpa102"},{"name":"InstanceName","value":"/"}],"metricValue":91,"webTestName":null}]},"subscriptionId":"933c2f10-9eff-49d0-a490-60ce1c3a0c72","resourceGroupName":"eu-hub-prd-aut-rg001","resourceName":"EU-HUB-MON-LAWS-01","resourceType":"Microsoft.OperationalInsights/workspaces","resourceId":"/subscriptions/933c2f10-9eff-49d0-a490-60ce1c3a0c72/resourceGroups/eu-hub-prd-aut-rg001/providers/Microsoft.OperationalInsights/workspaces/EU-HUB-MON-LAWS-01","portalLink":"https://portal.azure.com/#resource/subscriptions/933c2f10-9eff-49d0-a490-60ce1c3a0c72/resourceGroups/eu-hub-prd-aut-rg001/providers/Microsoft.OperationalInsights/workspaces/EU-HUB-MON-LAWS-01"}}}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2022 03:31 AM
Hi Ankur,
Can you please help me why we used parser.decode(reqbody);
can we use encode inplace of decode. Please help me the difference between between encode and decode
Regards,
Anuhsa
