Scripted REST API can only get one record

ABCD88852527207
Tera Expert

Hi Experts,

 

I have the following Scripted REST API. 

 

As the log showed, it could get 3 different Case Records.

SystemsGo_1-1726723356274.png

 

But when I do test from API explorer and post man, it displayed one record.

SystemsGo_2-1726723414106.png

Is there anything wrong with coding? how to fix that?

 

 

(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {

    var jsonData = [];
    var rec = new GlideRecord("sn_customerservice_case");
    rec.addEncodedQuery("account=f9028d7d1b343510feb9628b234bcb16^ORaccount=1a71df4c1bcb4410f1b487f7cc4bcbe6^stateIN3,6^opened_at>=javascript:gs.beginningOfLast12Months()");
    rec.query();
    var count = 3;
    while (rec.next()) {
        count--;
        var item = {
            id: count,
            name: 'item' + count,
            number: rec.number
        };
        gs.info(item.number);
        jsonData.push(item);
        if (count == 0) {
            break;
        }

    }
    response.setBody(jsonData);
    response.setContentType('application/json');
    response.setStatus(200);

})(request, response);

Long Duong
Kilo Sage

Hi there,

I think there is bug in your JS coding. To fix it, please replace "number: rec.number" with "number: rec.getValue('number')"

Please mark my comment helpful if the issue is resolved.

Thank you and have a nice day!

Lösung in ursprünglichem Beitrag anzeigen

Hi Long,

 

Thank you for your reply. It worked for me.

Thank you.

I think the following doc should be updated.

https://docs.servicenow.com/bundle/washingtondc-api-reference/page/integrate/custom-web-services/ref...

Hi, 

Thank you for your confirmation. If it worked for you, can you please mark my comments is solution or helpful?
About the document, I think it is still good. Because you can use [[number: rec.number + '']] also to convert it to string type. Hope it is clear for you.

 

Thanks

Lösung in ursprünglichem Beitrag anzeigen