How to get the Variables of RITM using REST Method

Priya Gautum
Kilo Guru

Hi Team

Can you please tell me how to get the Variables of RITM using Rest Method.

Regards,

Priya

1 ACCEPTED SOLUTION
16 REPLIES 16

AbhishekGardade
Giga Sage

Hello Priya,
Check out this blog for your solution:

https://snprotips.com/blog/2016/7/15/scripted-rest-apis-in-servicenow-how-to-retrieve-catalog-item-v...

You can use the REST API to pull data from any table, so it's just a matter of knowing where the data is and how to find what's related to your Requested Items (RITM).   Variables are stored in their own table, not as a field on the RITM record, so you need to decipher the relationship before you can try to query for what you want.

Funny enough, variables are actually called "Options" once they have a value assigned and are stored in the Options table [sc_item_option].   The table called "Variables" ([item_option_new]) only stores the definition of that variable (i.e., it's type, associated question, hint, etc.).   So the Options table is where you want to look at for your actual values.

To get to the Options you are looking for, you will need to look at a Many-to-Many table [sc_item_option_mtom] relating your Requested Items to their Options.   So if you have the sys_id of your RITM handy:

  1. you would query [sc_item_option_mtom] to get a list of the Options (your variables) that belong to it.
  2. then you can use that list of option sys_id's to query [sc_item_option] for the values you are after.

 If you need help querying with the REST API, please check the wiki article here:

Table API - ServiceNow Wiki

Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade
Hexaware Technologies

Thank you,
Abhishek Gardade

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Priya,

Do you want to send the RITM variables to some 3rd party using REST or want to consume ServiceNow REST API endpoint to get the RITM variables?

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Hi Ankur

I will be using some 3rd party.

 

How can we achieve this in Scripted REST API?