How can I get the variable value from the RITM record?

Danny Sun
Tera Guru

I want to get a variable value from the RITM record, the value is from one of the request form. I try to get it from the 'sc_item_option_mtom' table, but i did not work.

var scOption = new GlideRecord('sc_item_option_mtom');

scOption.addQuery('request_item.number','RITM2061426');

scOption.query();

while(scOption.next()){

        //get the value of the term_date

        gs.log("Term Date="+scOption.sc_item_option.term_date.value);

}

Are there any questions about this?

Thanks.        

1 ACCEPTED SOLUTION

bt6lw
Giga Contributor

Don't have my reference handy of our implementation. I am quite sure however, you should be able to do a gliderecord lookup to the sc_req_item. This is assuming your variable is attached here - which it normally would be - but i've seen some funnny implementations.





so... you can copy this exactly -   just change the "YOURVARIABLENAME" with the name of the variable you are referencing. (This would be the "item_option_new" table. The element is "name'.






var gr = new GlideRecord('sc_req_item');


gr.addQuery('number', 'RITM2061426');


gr.query();


if (gr.next())


{


gs.log(gr.variable_pool.YOURVARIABLENAME);


}




Please let me know if you struggle, I use this kind of lookup for many different validations / process steps from Service Catalog.



Regards


Willem.


View solution in original post

10 REPLIES 10

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Danny



Try the below script:


var scOption = new GlideRecord('sc_req_item');


scOption.addQuery('number','RITM2061426');


scOption.query();


while(scOption.next()){


var server = scOption.variables.server_name;//Replace "Server_name" with your variable name


gs.addInfoMessage(server);


}



Let me know if you have any questions



Thanks and Regards


Pradeep Sharma


Hi Pradeep,



I try to use the script you mentioned, but it still don't to work. I output this: scOption.variables.term_date, but the value is "undefined". It seem that it can't get the variable value. Thanks for you help.




Regards,


Danny


I don't think it should be the script issue


Please check if you can get the value of "term_date" at "RITM" level with the help of business rule.


Also if you can replicate it on any demo instance, I can verify and help you there.




Thanks


Pradeep Sharma


Thank you very much. This question has been resolved.



Regards,


Danny