Need help in storing response body in one of the field in staging table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2022 09:45 PM
Hi,
I have scripted rest api and from there I'm calling script include.
I have to set the response (which I'm getting fro third party) in custom response (string field) on staging table.
Any help?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2022 09:56 PM
HI @Tanya
You can check this below example video:
https://www.youtube.com/watch?v=4lvCIonvPso&t=124s
Thanks,
Murthy
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2022 10:40 PM
Hi
Actually we are using scripted rest API

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-14-2022 06:07 AM
Hi Tanya,
Not sure of the question. So what is the problem? Just set a return in Scripted REST API script step to return a custom response.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2022 09:08 PM
Hi
Sorry for the confusion.
So here we we will be giving the ServiceNow endpoint url to third party.
I have written scripted rest api from which I'm calling script include.I'm kind of stuck in script include, where I'm checking one field and if it is null I want to send response with a message.
I tried using setMessage but it shows that parsing unexpected token. Though after setting the log i got to know it does check validate the condition and I can see it in log.
Pasting the code below:
(function executeRule(current, previous /*null when async*/) {
var createTicket = Class.create();
createTicket.prototype = {
initialize: function() {},
createIncidents: function(request, response) {
var requestBody = request.body;
var str = JSON.stringify(requestBody.data);
var RequestPayload = str;
var parser = new JSONParser();
var result = parser.parse(str);
var CID = result.uniqueField;
gs.log("CID:" + CID);
if (CID == null) {
gs.log("Bad request");
} else {
gs.log("Good Request");
}
var grTicket = new GlideRecord('u_createTicket');
grTicket.initialize();
grTicket.setValue('u_request_payload', result.str);
grTicket.setValue('u_logicapprun_id', result.logicapprunid);
grTicket.setValue('u_error_code', result.errorcode);
grTicket.setValue('u_publisherrunid', result.publisherrunid);
grTicket.setValue('u_interface_id', result.interfaceid);
grTicket.setValue('u_impact', result.impact);
grTicket.setValue('u_source', result.source);
grTicket.setValue('u_urgency', result.urgency);
grTicket.setValue('u_actionname', result.actionname);
grTicket.setValue('u_destination', result.destination);
grTicket.setValue('u_description', result.description);
grTicket.setValue('u_error_systemname', result.error_systemname);
grTicket.setValue('u_error_time', result.error_time);
grTicket.setValue('u_logicappname', result.logicappname);
grTicket.setValue('u_shortdescription', result.shortdescription);
grTicket.setValue('u_blobname', result.blobname);
grTicket.setValue('u_request_payload', RequestPayload);
grTicket.setValue('u_unique_identifier', result.uniqueField);
return grTicket.insert();
},
type: 'createTicket'
};
})(current, previous);