- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2017 10:16 PM
Hi,
I need help in sending response from Servicenow to Third party using REST API.
I have a custom table and need to embed Record number in this as a request and SNOW has to send response with 10 fields information. 3rd party will not send sys_id and so i need to have an scripted REST so that Record number in request.
Please help me in this. They need only response.
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2017 09:11 PM
Hi Maneesh,
Please try the below code it should work.
//var reqId = request.queryParams.rec_number;
var reqId = request.pathParams.rec_number;
var respBody = {};
var req = {};
var content = [];
var i=0;
var gr = new GlideRecord('table_name');
gr.addQuery('number',reqId);
gr.query();
while(gr.next()){
req = {};
req.number = gr.number;
req.short_description = gr.short_description;
req.priority = gr.priority;
content[i] = req;
i++;
}
if(content.length == 0 ){
respBody.status = 'Error' ;
respBody.content = 'No record found';
}else{
respBody.status = 'success';
respBody.content = content;
}
response.setContentType('application/json');
response.setStatus(200);
response.setBody(respBody);
-Udhay
Please Hit like, Helpful or Correct depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2017 01:52 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2017 04:16 AM
Hi Udhay,
Can you please help me in this. I am getting error as size constraint. Can you help me in getting rid from this error.
Thanks for the help!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2017 09:11 PM
Hi Maneesh,
Please try the below code it should work.
//var reqId = request.queryParams.rec_number;
var reqId = request.pathParams.rec_number;
var respBody = {};
var req = {};
var content = [];
var i=0;
var gr = new GlideRecord('table_name');
gr.addQuery('number',reqId);
gr.query();
while(gr.next()){
req = {};
req.number = gr.number;
req.short_description = gr.short_description;
req.priority = gr.priority;
content[i] = req;
i++;
}
if(content.length == 0 ){
respBody.status = 'Error' ;
respBody.content = 'No record found';
}else{
respBody.status = 'success';
respBody.content = content;
}
response.setContentType('application/json');
response.setStatus(200);
response.setBody(respBody);
-Udhay
Please Hit like, Helpful or Correct depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2017 09:25 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2017 09:37 PM
Sorry my bad I have used wrong pathparams in request 1 st line. Now its working
Thanks a ton udhay.