- 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 02:20 PM
I was getting 1 record and were very close to use to push for all records.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2017 02:22 PM
Still it is your solution Shishir. I just tuned the script a bit. You owe the credit.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2017 02:25 PM
that's ok Antin. Learned new way, how to push data in JSON type variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2018 04:34 PM
Hello,
I need to create a Webservice API where input is: Sys ID of any record and output is: all *related* active records to that sys id. The relationships between the tables is maintained in Relationships under system definition.
Could you please guide me how to implement this? Sample code would be great.
Input: Sys ID of the record
Output: All *RELATED* active records from *VARIOUS* tables (in the following JSON format):
{
"result": [
{
"Sys ID": "5520267",
"CI Name": "Record 1",
"Table Name": "u_table_a"
},
{
"Sys ID": "5520367",
"CI Name": "Record 2",
"Table Name": "u_table_a"
},
{
"Sys ID": "8331210",
"CI Name": "Record 1",
"Table Name": "u_table_b"
},
{
"Sys ID": "8321210",
"CI Name": "Record 2",
"Table Name": "u_table_b"
},
{
"Sys ID": "3042006",
"CI Name": "Record 3",
"Table Name": "u_table_b"
},
{
"Sys ID": "4509847",
"CI Name": "Record 1",
"Table Name": ""u_table_c"
}
{
"Sys ID": "4509247",
"CI Name": "Record 2",
"Table Name": ""u_table_c"
}
]
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2017 12:29 PM