- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-27-2022 10:01 PM
HI All,,
Appreciate your help..!
My Requirement : i have the catalog item sysid, Requested for, and variable value. Here i have to Query sc_req_item with these details need to find the RITM number .
Simple Query :
requestItem.addQuery('variables.variablename','IN','variable Value');
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-28-2022 05:28 AM
Hi,
you can directly use encoded query to check the value contains and no need to iterate over all RITMs
give the variable sysId here; you can find it from variables table
var Item = new GlideRecord('sc_req_item');
requestItem.addQuery('request.requested_for', 'user sysid');
requestItem.addQuery('cat_item', 'catalog item sys id');
requestItem.addEncodedQuery("variables.variableSysId", "variable value");
requestItem.query();
var found = requestItem.hasNext();
gs.info('Found ' + found);
Regards
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-27-2022 10:12 PM
Try something like below
var requestItem = new GlideRecord('sc_req_item');
requestItem.addQuery('requested_for', 'user sysid');
requestItem.addQuery('cat_item', 'catalog item sys id')
requestItem.query();
if(requestItem.next()){
if(requestItem.variables.variablename = "variable Value"){
//DO SOMETHING HERE.....
}
}
Muhammad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-27-2022 10:18 PM
Just for explanation, variables doesn't exist on RITM table instead variables are stored in a separate table so you cannot apply query on variables while your glide record is on requested item table.
These are the tables that hold variables and variable values.
M2M table to request item
sc_item_option_mtom.request_item
M2M table to variable
sc_item_option_mtom.sc_item_option
Muhammad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-27-2022 10:38 PM
I have followed your query.. But here my variable is a list collector and holding two sysid values.
from these 2 sys id's i want to fetch the record for specific sysid.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-28-2022 12:16 AM
Hey
You can update the if condition within the while loop as below
var ritmVariableValue = requestItem.variables.variablename;
ritmVariableValue = ritmVariableValue.toString();
if(ritmVariableValue.indexOf("variable Value") > -1){
//DO SOMETHING HERE
}
Muhammad