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.

How can I use the query filter of the rest api using the display value.

guptashalini041
Kilo Contributor

I would like to create rest api which provides all the task associated with any RITM.

I want to pass the RITM number like (RITM1231) in query parameter as end user don't have the sys_id of RITM.

How can I achieve it. Please find attached the screen shot for your reference.

 

Thank you

1 ACCEPTED SOLUTION

Colin Webster
Mega Expert

The display value of a reference field is just one of the fields of the referenced table so you would just need to dot-walk to the display value field.

find_real_file.png

View solution in original post

2 REPLIES 2

Colin Webster
Mega Expert

The display value of a reference field is just one of the fields of the referenced table so you would just need to dot-walk to the display value field.

find_real_file.png

harishdasari
Tera Guru

Hi Shalini,

In your case you should create an Scripted REST API and use the GET method.

In the scripted REST API, use the GET method and give the relative path as sys_id.

find_real_file.png

 

Now write the logic in the scripted rest api like below

// implement resource here
var toNum = request.pathParams.sys_id;
var body = {};
var sc = new GlideRecord('sc_req_item');
sc.addQuery('active', 'true');
sc.addQuery('number', toNum);
sc.query();

while(sc.next())

{

//write your logic here to return the tasks.

}

 

Hope this might be helpful to you.

Thank you.