- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2022 07:24 PM
I have created Scripted REST API for inbound create incident using POST method, while testing I can see only incident is creating but not test values are populating in the same incident, please help me in modifying the following code which I used.
(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var gr = new GlideRecord("incident");
var requestBody = request.body.nextEntry();
gs.log("requestBody: "+requestBody,"rest");
var sd = requestBody.short_description;
gs.log("sd: "+sd,"rest");
gr.initialize('short_description',request.body.short_description);
gr.initialize('description', request.body.description);
gr.initialize('priority', request.body.priority);
gr.initialize('category', request.body.category);
gr.initialize('sub_category', request.body.sub_category);
gr.initialize('correlation_id', request.body.correlation_id);
gr.initialize('type', "soc_inc");
var socincid = gr.insert();
return gr.getValue('number');
})(request, response);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2022 08:44 PM
Hi,
seems you are not sending the JSON request correctly and not correctly parsing it
it should be something like this
body:
{
"short_description":"test",
"description":"test1"
}
Script:
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
// implement resource here
var incomingBody = request.body.dataString;
var parsedData = JSON.parse(incomingBody);
var desc = parsedData.description;
var shortDesc = parsedData.short_description;
var gr = new GlideRecord("incident");
gr.initialize();
gr.description = desc;
gr.short_description = shortDesc;
gr.insert();
var body = {};
body.number = gr.number;
response.setBody(body);
})(request, response);
Regards
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-05-2022 08:44 PM
Hi,
seems you are not sending the JSON request correctly and not correctly parsing it
it should be something like this
body:
{
"short_description":"test",
"description":"test1"
}
Script:
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
// implement resource here
var incomingBody = request.body.dataString;
var parsedData = JSON.parse(incomingBody);
var desc = parsedData.description;
var shortDesc = parsedData.short_description;
var gr = new GlideRecord("incident");
gr.initialize();
gr.description = desc;
gr.short_description = shortDesc;
gr.insert();
var body = {};
body.number = gr.number;
response.setBody(body);
})(request, response);
Regards
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-05-2022 09:33 PM
Thanks Ankur for your quick reply, its working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2022 10:24 PM
Can you please share code for the update incident as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2022 09:38 PM
Can you please share code for the update incident as well.