- 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:56 AM
Hello Sameer,
Minor modification..
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;
- Pradeep Sharma
- 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
