Using RITM Variables value in GlideRecord.

Mohan Mallapu
Kilo Sage

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 :

var Item = new GlideRecord('sc_req_item');
requestItem.addQuery('requested_for', 'user sysid');
requestItem.addQuery('cat_item', 'catalog item sys id')
requestItem.addQuery('variables.variablename','IN','variable Value');
requestItem.query();
if(requestItem.next()){
//if RITM exist need to something here
}
this is how i want to find the RITM number. but this logic is not working .. Could anyone please help me on this ..
1 ACCEPTED SOLUTION

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

9 REPLIES 9

MrMuhammad
Giga Sage

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.....
   }
}
Regards,
Muhammad

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

Regards,
Muhammad

@Muhammad  Thanks for the Quick reply.

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.

Hey @Mohan Mallapu,

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
}

 

Regards,
Muhammad