How to get variables and variable values via a REST call?

Nick9
Kilo Contributor

Hello,

 

We are making a REST call that filters certain tasks and then for each one of them we run a workflow in another tool. So far, so good.

The problem is that the call to "/api/now/table/sc_task?state=1&short_description=****" does not bring the value of the variables in that particular task. 

I assume that a secondary call is needed - and for as much as I know it has to be to sc_item_option_mtom (where ritm variables are stored). Even if we make this call - the answer does contain the info needed, and a third call would be needed for each variable to sc_item_option. Not to mention that all is in sys_id format (I don't get the actual question display value, but its sys_id)

Is there a way to obtain the values of the variables without making these many calls? I would be satisfied with the original call - which gives me the task number or the ritm number, and a second call where I can get the variables and their values. Can this be done?

 

Thank you

Nick

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you will have to do 2 API calls

1) get RITM for your SC Task

2) Then query with variables.xxxx=YYYYYY for those RITMs

OR

You need to create Scripted REST API and then get the record matching the query

refer below link

Scripted REST APIs & Retrieving RITM Variables via SRAPI

Regards
Ankur

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

@Nick 

Thank you for marking my response as helpful.

If my response helped you please mark it correct to close the question so that it benefits future readers as well.

Regards
Ankur

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

Hi Ankur,

 

Can you explain a little more #2. Towards what table should we make that call and is xxxx = name variable and what is yyyy?

Regards,

Nick

Hi,

just checked this link and it mentions you can get the variables from sc_task table API

API to get SCTASK variables

https:<instance url>/api/now/table/sc_task?sysparm_query=number=<sc_task number>&sysparm_display_val...

We can directly add the variables.<variablename> in the link.

Regards
Ankur

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