Scripted Rest API Not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-13-2022 06:18 AM
Hi All,
below is the script that i written on scripted rest api. but its not working when i send data like https://google.com/gtre
can any one help me on this
(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var obj = {};
obj.number = request.pathParams.number;
obj.worknotes = request.pathParams.work_notes;
var gr = new GlideRecord("sc_req_item");
gr.addQuery("number", obj.number);
gr.query();
if (gr.next()) {
gr.work_notes = obj.worknotes;
gr.update();
response.setBody(obj);
}
})(request, response);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-13-2022 06:23 AM
Hi,
you are not hitting the ServiceNow endpoint so how the scripted rest api would run?
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
‎01-13-2022 06:29 AM
Hi Ankur,
i created endpoint as well. here is the endpoint
PUT https://instance.service-now.com/api/396051/request/{number}/{work_notes}
but i receiving the response like.
{
"error": {
"detail": null,
"message": "Requested URI does not represent any resource"
},
"status": "failure"
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-13-2022 07:10 AM
Hi,
why not use POST method and include body
Like this
{"number":"RITM001", "work_notes":"my testing"}
HTTP - POST
Resource path - /api/65080/testing_incident_update
Script
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
// implement resource here
var incomingBody = request.body.dataString;
var parsedData = JSON.parse(incomingBody);
var ritm = parsedData.number;
var group = parsedData.work_notes;
var body = {};
var gr = new GlideRecord("sc_req_item");
gr.addQuery("number", ritm);
gr.query();
if (gr.next()) {
gr.setValue('work_notes', group);
gr.update();
body.status = "Success";
}
else{
body.status = "Failure";
body.statusMessage = "RITM not found";
}
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
‎01-13-2022 07:24 AM