Fetching "Variables" values in REST API

s_gatade
Kilo Contributor

Dear all,

Our ServiceNOW Setup has some custom variables defined for Request Items. e.g. "Requested for:". Is it possible to get the values for these parameters defined under Variables via REST API Dot Walking or any other REST option?

Thanks in advance!

S. Gatade

7 REPLIES 7

Mike Allen
Mega Sage

In Geneva, you could set up a Scripted REST API that would allow you to pass a parameter and return the variables using current.variable.



Pre-Geneva, you can do this with SOAP.



I don't know that you can do it with a table API, though.


Brian Dailey1
Kilo Sage

Hi Shailendra,



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




Good luck,


-Brian


Hi Brian,



Thanks for the elaborate answer. I do now have a better idea about how this can be achieved but the only problem seems to be the knowledge about the REST response structure for the sc_item_option and sc_item_option_mtom response. Is there any wiki article that describes sample response JSON's for all the tables?



I am getting an ACL error on top level table (e.g. sc_item_option) but I guess thats happening since I do not have rights on all the collections within the tables. May be if I am able to filter on the CI's I am allowed to view then the ACL's should not be a problem.



Thanks and regards,



Shailendra


Hi Shailendra,



Check that Table API link (above) again, there are two examples each for the JSON and XML response formats.   You could also test any table using the methods listed in a browser   (e.g. http://(instance)/api/now/table/sc_item_option) to get a sample response and see what you should be expecting.




Thanks,


-Brian