How to get the selected value by using Reference or Lookup in catalog item variables with Rest API

竜太畠
Tera Contributor

I am currently creating a Rest API to get the value of ServiceNow catalog variables from an external system.

 

In cases where reference or lookups are used with variables, I believe the “Value” field in the “sc_item_option” table contains the sys_id information of the referenced table.

 

I think you can get the name of the referenced table from the “reference” field or the “lookup_table” field in the item_option_new table. However, when I try to find out which field in the referenced table was used to display the target variable, I cannot find that information in the item_option_new table.

 

Using the example of referring to the sys_user table, the name shown on the screen is the “first_name” field in the “sys_user” table. You can identify the user in “sys_user” by using the Value’s sys_id in the “sc_item_option” table and the Lookup table field in “item_option_new.” However, after that point, it is not possible to tell which field, like “user_name” or “first_name,” in the sys_user table is actually shown on the screen.

If anyone knows how to identify the field of the referenced table selected on the screen when using reference or Lookup with catalog item variables in the Rest API, please kindly teach me.

1 REPLY 1

@Ankur Bawiskar 
Thank you for your quick reply.

Is it correct to understand that the value of any field in the reference table to be handled must be decided in advance by the program issuing the API or within the ServiceNow script API, and then obtained?

Using the example of sys_user, let’s say there is a variable on the screen called “user_display” that shows the “first_name” field from the sys_user table. If the API side also wants to use the value selected by the “user_display” variable on the screen, it means that the program needs to be set so that the value obtained from the sys_id in the “user_display” variable is the “first_name” field value from the sys_user table. Is that correct?