- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2017 11:33 AM
Hi,
I have to created scripted rest api ,To get all the incident number from caller_id .
Thanks in advance
Solved! Go to Solution.
- Labels:
-
Integrations
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2017 02:16 PM
Hi Sneha,
The below script should work.
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var jsonStr = {"incidents":[]};
var gr = new GlideRecord('incident');
gr.addQuery('caller_id',request.queryParams.caller_id);
gr.query();
while(gr.next()){
var incidentOb = {};
incidentOb.number = gr.number + '';
incidentOb.short_description = gr.short_description + '';
jsonStr['incidents'].push(incidentOb);
}
return jsonStr;
})(request, response);
Hope this helps. Mark the answer as correct/helpful based on impact.
Thanks
Antin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2017 12:36 PM
Also, I would strongly suggest to use Table API for these queries, as you dont have to maintain these scripts. If it is for your learning purpose, it is fine. Otherwise, these are the requirements why Table APIs are available for.
Thanks
Antin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2017 12:52 PM
Hi Antin,
I tried using sys_id also in Shsishir's code through rest api explorer but its not showing any response( not even response box) .
can you please let me how can I achieve( get all the incident number of a caller when I pass caller_id in the query parameter through rest api explorer)
var body = request.body.data;
var caller_id = body.caller_id;
var gr = new GlideRecord('incident');
gr.addQuery('active',true);
gr.addQuery('caller_id', "=", "c9884ac30a0a0bdb3879454e8f02774e");
gr.query();
while (gr.next()) {
return {
"number": gr.number(),
}
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2017 12:58 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2017 01:04 PM
Hi Shishir,
Thanks so much for your reply.
But I am looking for scripted rest api not table api .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2017 02:16 PM
Hi Sneha,
The below script should work.
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var jsonStr = {"incidents":[]};
var gr = new GlideRecord('incident');
gr.addQuery('caller_id',request.queryParams.caller_id);
gr.query();
while(gr.next()){
var incidentOb = {};
incidentOb.number = gr.number + '';
incidentOb.short_description = gr.short_description + '';
jsonStr['incidents'].push(incidentOb);
}
return jsonStr;
})(request, response);
Hope this helps. Mark the answer as correct/helpful based on impact.
Thanks
Antin