Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Obtaining all related data for a bundle with REST

Alejandro Orteg
Kilo Explorer

Hi,
I am new to Service Now development and do not have any historical knowledge with respect to internals and table structure. Can anyone provide a brief summary of the steps involved to obtain a request, its associated ritm's and enumerate their tasks?

I will know the request # to start, so after reading the api reference, I can easily obtain that data:

curl "https://instance.service-now.com/api/now/table/sc_request?number=REQ0000000" \
 --request GET \
 --header "Accept:application/json" \
 --user 'xxx':'yyy' --silent |jq .

However, from that, I am not clear on how to infer the sc_req_item. Presumably, I construct a query on that table that constrains the items to those related to the sys_id of the request?

And lastly, whatever strategy is required there, I assume it is similar to enumerate the tasks for the a given item once I decide which one is of interest?

Thanks for any guidance!

1 ACCEPTED SOLUTION

Brad Tilton
ServiceNow Employee

It sounds like you've got the process down if you're using the table api. The sc_req_item table has a field that references the sc_request table called request. The sc_task table has a field that references the sc_req_item table called request_item. Passing the appropriate sys_ids into those fields will give you the lists of items and tasks in the response. You can also use the number of the item rather than the sys_id if you want to by doing something like request.number=REQ0000000 from the item or even request_item.request.number=REQ0000000 from the task.

I would use the REST API Explorer we provide to get comfortable with the rest api overall as it gives you a GUI for building queries you can then use.

Another option would be to write your own Scripted REST API where you would execute some server side JS in ServiceNow when a custom endpoint is hit and return all of the information you're looking for in one rest call. The learning curve on this what is a bit higher due to the SN JS you'd have to write.

View solution in original post

2 REPLIES 2

Brad Tilton
ServiceNow Employee

It sounds like you've got the process down if you're using the table api. The sc_req_item table has a field that references the sc_request table called request. The sc_task table has a field that references the sc_req_item table called request_item. Passing the appropriate sys_ids into those fields will give you the lists of items and tasks in the response. You can also use the number of the item rather than the sys_id if you want to by doing something like request.number=REQ0000000 from the item or even request_item.request.number=REQ0000000 from the task.

I would use the REST API Explorer we provide to get comfortable with the rest api overall as it gives you a GUI for building queries you can then use.

Another option would be to write your own Scripted REST API where you would execute some server side JS in ServiceNow when a custom endpoint is hit and return all of the information you're looking for in one rest call. The learning curve on this what is a bit higher due to the SN JS you'd have to write.

Alejandro Orteg
Kilo Explorer

Thanks for the insight Brad, I was unaware of the relational functionality available and that will greatly simplify my needs.