How to easily access RITM variables via script when your RITM is not the current record.
I’ve seen this question come up a few times lately, so I thought I’d take a moment to make an article about it. There are certain situations where you need to pull data from RITM variables where the RITM itself is not the current record (such as when running a background script) and the way to accomplish this isn’t overly obvious.
Partially this is because the way RITM variable values are stored is not easy to dissect and actually involves several tables, but also partially because it’s easy to overlook some features that make it easier to accomplish than you might think.
Since you may be looking for an explanation on how variables are actually stored in the tables, I’ll provide a breakdown of the structure. There are 3 main tables involved; sc_req_item, sc_item_option_mtom and sc_item_option.
The actual values are stored in the sc_item_option table, but that able alone isn’t enough. The sc_item_option_mtom table is the key. In order to find the values for a specific RITM, you have to query the sc_item_option_mtom table for the records where the request_item is your RITM. From there you can take the value of the sc_item_option field and query the sc_item_option table to find the record that hold the specific value for that variable on your RITM.
Following this path, you would need to write three nested queries to get to the sc_item_option records that you want. The good news is, there is an incredibly easy short-cut you can use.
Let’s say you have a RITM with a number of RITM0010014 that has 3 variables on it, summary, description and due_date. From any server-side script you can easily get the values of those variables like this:
var values = '';
var ritm = 'RITM0010014';
var gr = new GlideRecord('sc_req_item');
gr.addQuery('number', ritm);
gr.query();
while(gr.next()) {
values += 'Summary is: ' + gr.variables.summary + ',';
values += 'Description is: ' + gr.variables.description + ',';
values += 'Due Date is: ' + gr.variables.due_date;
}
gs.info(values);
Easy, right? It’s identical to what you can do when your RITM is the value for current!
If you found this helpful or informative, please be kind and click appropriately!
Maybe bookmark this for later reference ![]()
https://www.servicenow.com/community/developer-articles/how-to-easily-access-ritm-variables-via-script-when-your-ritm-is/ta-p/2324796