Request Item variables via REST API

bernard6
Mega Expert

I have a Catalog Item that has variables.   When I perform a Get for a request Item for that Catalog Item (sc_req_item) via the REST API it doesn't return the values that were set for the variables on that Request Item.   Is there a way to have these included in the Get or a way to query that information from the REST API?

1 ACCEPTED SOLUTION

joshua_bice
Giga Expert

You need to use the variable ownership table (sc_item_option_mtom). Query by the Request Item and you'll get a list of variables for it.


View solution in original post

16 REPLIES 16

Hi Niranjan,



You should be able to look up those items in the table Joshua referenced above (sc_item_option_mtom).   There will be an entry for each variable.   So you can filter it for the requested item that you're looking for and then select the information for each of the variables for that requested item.   So using a simple query it would look something like this:



var req_var = new GlideRecord("sc_item_option_mtom");


  req_var.addQuery('request_item',"SYS_ID_OF_REQ_ITEM");//SYS_ID_OF_REQ_ITEM would be the sys_id of the request item your looking up


  req_var.query();


while (req_var.next()) {


        var req_question = sc_item_option.item_option_new;


        var req_answer = sc_item_option.value


}



You could of course add these to an array, hash table, or whatever works for what you're trying to do.



Thanks,


David Bernard


Hi Bernard,



Thanks for the information. But i figured out how to access them.


we can use "current.variables.variable_name" to target variables on the requested item form.


Hey David,


                                  i have tried your script, but i didn't get any response, i just need to get the request number against variable name of raised item, can you just provide the sample example that helps me to get the raised request details against variable name of catlogue item. or some workaround solution.



Thanks in advance


Thank you for the answer..but I have another question?While query sc_item_option_mtom  i need to filter only the visible variables on the forms.

But i am getting all the variables. How we can do that?

 

tltoulson
Kilo Sage

Hi David,



If you are using JSONv2, you can accomplish this with the displayVariables parameter: JSONv2 Web Service - ServiceNow Wiki