how to fetch multiple record using get scripted rest api

ramancoder
Tera Contributor

ramancoder_0-1669020448880.png

not getting correct output

1 ACCEPTED SOLUTION

Community Alums
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
Tera Guru

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

 

Richard