- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2022 12:48 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2022 01:37 AM
Hi @ramancoder ,
If you want to fetch data for multiple records and send a response, then you need to use an array of objects. Here's how the code will look like:
var output = [];
var gr = new GlideRecord('incident');
//add your encoded query here
gr.query();
while(gr.next()){
var temp = {};
temp[gr.number] = gr.description.toString();
output.push(temp);
}
response.setBody(output);
Feel free to mark correct, If I answered your query.
Will be helpful for future visitors looking for similar questions. 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2022 12:58 AM
Hello @ramancoder,
Please use the rest api explorer for creating an API for the above requirement.
I have created an API for you as below as per your requirement please put you instance name and check.
https://<instance_name>.service-now.com/api/now/table/incident?sysparm_query=category%3Dsoftware%5Epriority%3D2&sysparm_fields=number%2Cdescription&sysparm_limit=1
Please Mark my answer as correct.
BR,
Nayan.
Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2022 01:20 AM
Ramancoder,
Your code does not really make sense. You are retrieving details from an incident and are then placing the constructed body into the response object. If you are planning to make an API call for these details, you need to place the contstructed body into the request body and not the response body.
Can you give the use case of what you are trying to achieve and we will be able to help you more.
Thanks and Regards,
Richard
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2022 01:37 AM
Hi @ramancoder ,
If you want to fetch data for multiple records and send a response, then you need to use an array of objects. Here's how the code will look like:
var output = [];
var gr = new GlideRecord('incident');
//add your encoded query here
gr.query();
while(gr.next()){
var temp = {};
temp[gr.number] = gr.description.toString();
output.push(temp);
}
response.setBody(output);
Feel free to mark correct, If I answered your query.
Will be helpful for future visitors looking for similar questions. 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2022 01:53 AM
Thanks sir.Executed successfully.