Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Case API returning "record not found" when querying with number

ManasiP
ServiceNow Employee
ServiceNow Employee

When we used the GET with the case number to query case by id, the result is "record not found". If i changed to the case sys_id, everything works fine.

I checked and found that it's failing when we do if (gr.get('number')), which returns false, so the rest of the logic is not executed.

Has anyone faced this issue and been able to resolve it?

1 ACCEPTED SOLUTION

@ManasiP 

as you can see it's using GlideRecordSecure so it will evaluate ACL for your API user

is that user able to see that in UI using normal table list?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

8 REPLIES 8

M Iftikhar
Tera Sage

Hi @ManasiP,

If you want to query a record with the Case Number please also provide the value

if(gr.get('number','YOUR_CASE_NUMBER'))

because this is the required parameter for get() method

MIftikhar_0-1765281417064.png

MIftikhar_0-1765281593904.png


If my response helped, please mark it as the accepted solution so others can benefit as well.

Thanks & Regards,
Muhammad Iftikhar

If my response helped, please mark it as the accepted solution so others can benefit as well.

ManasiP
ServiceNow Employee
ServiceNow Employee

HI @M Iftikhar , I checked this but there are many api's oob which directly queries on number or any other field by using gr.get("CS0002010") and this is very basc api, its failing in a customer instance but passing on other instances.
Also, the way "query case by id" api is written on case table, the logic directly queries on number.

ManasiP_0-1765281779542.png

 

gr.get("CS0002010") works only if the string matches the record’s sys_id or if the instance internally allows lookup by display value (like number). This behavior varies across instances due to differences in platform version, ACLs, or configuration.

The correct and reliable way to query by number is:

gr.get('number', 'CS0002010');

or use a query:

gr.addQuery('number', 'CS0002010'); gr.query();

 

Ankur Bawiskar
Tera Patron
Tera Patron

@ManasiP 

is it working with admin?

If yes and not with non-admin then check this

-> CSM Query rule

-> Query BR on Case table is restricting

it's an OOTB scripted REST API and here is the info, you can see which endpoint and HTTP Method is good for you

AnkurBawiskar_0-1765282253610.png

 

it worked for me as admin with Both Number

AnkurBawiskar_1-1765282253749.png

 

 

AnkurBawiskar_2-1765282253627.png

 

https://instanceName.service-now.com/nav_to.do?uri=sys_ws_definition.do?sys_id=771aaa2f5342030097a2ddeeff7b127d

AnkurBawiskar_3-1765282270289.png

 

 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader