We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

how to fetch multiple record using get scripted rest api

ramancoder
Tera Contributor

ramancoder_0-1669020448880.png

not getting correct output

1 ACCEPTED SOLUTION

Not applicable

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. 🙂

View solution in original post

5 REPLIES 5

Richard Hine
Tera Guru

Arent you still setting the body into the response rather than the request? Seems backwards to me....

 

Richard