result of Latest 5 records from the API query

htharun
Tera Contributor

Can any one please help me with the query where I can display Latest 5 Change records.

This is as per execution date. Like 2022 change details should be first and then 2021 details.

But when using the below query the details are shuffled.

 

https://companyname.service-now.com/api/now/table/change_request?cmdb_ci=21effd8d13d61b08c9dfb607614...&sysparm_order=sys_created_on&sysparm_order_direction=asc&sysparm_display_value=true

 

I also tried the below but couldn't get the desired output

<https://dev27348.service-now.com/api/now/table/incident?sysparm_limit=10&sysparm_offset=0>;rel="first",<https://dev27348.service-now.com/api/now/table/incident?sysparm_limit=10&sysparm_offset=10>;rel="next",<https://dev27348.service-now.com/api/now/table/incident?sysparm_limit=10&sysparm_offset=50>;rel="last"

1 ACCEPTED SOLUTION

Tony Chatfield1
Kilo Patron

Hi, your details show a sort field of 'sys_created_on', but your post states execution date; I don't think execution date is an OOB field, is it custom? if yes then this may be the field you need to order by, if not then OOB field 'Actual start' (work_start) might be the field that you want to order by. 

Also I am not sure that sysparm_order and sysparm_order_direction are valid for ServcieNow tabble API and I think that you need to roll your sort\order requirement into your sysparm_query

cmdb_ci=21effd8d13d61b08c9dfb6076144b0d1^ORDERBYDESCwork_start

 

/api/now/table/change_request?sysparm_query=cmdb_ci%3D21effd8d13d61b08c9dfb6076144b0d1%5EORDERBYDESCwork_start&sysparm_limit=5

Table API | ServiceNow Developers

View solution in original post

2 REPLIES 2

Tony Chatfield1
Kilo Patron

Hi, your details show a sort field of 'sys_created_on', but your post states execution date; I don't think execution date is an OOB field, is it custom? if yes then this may be the field you need to order by, if not then OOB field 'Actual start' (work_start) might be the field that you want to order by. 

Also I am not sure that sysparm_order and sysparm_order_direction are valid for ServcieNow tabble API and I think that you need to roll your sort\order requirement into your sysparm_query

cmdb_ci=21effd8d13d61b08c9dfb6076144b0d1^ORDERBYDESCwork_start

 

/api/now/table/change_request?sysparm_query=cmdb_ci%3D21effd8d13d61b08c9dfb6076144b0d1%5EORDERBYDESCwork_start&sysparm_limit=5

Table API | ServiceNow Developers

Community Alums
Not applicable

Not sure if possible from the Table API...I know you can do that with GlideQuery objects, but havent investigated if possible to pass it in the Table API in the URL (I mean like javascript&colon;new GlideQuery(.....) ). Still, I believe with a bit of test and trial you could actually do it .

 

 

Hope this gives you some hint or ideas.

 

Cheers,

Joro