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

Harish KM
Kilo Patron
Kilo Patron

Hi  there is no field called variable.variablename in RITM table so your query will fail. To get the variable value you need to do like below


var requestItem = new GlideRecord('sc_req_item');
requestItem.addQuery('requested_for', '1c8c17a307010110f1cbf48f7c1ed089');// user sysid
requestItem.addQuery('cat_item', 'e28ccc6307ad0110f1cbf48f7c1ed0ee'); //item sysid
requestItem.query();
if(requestItem.next()){
var getVariableValue = requestItem.variables.variablename;
if(getVariableValue =="yourvalue")
{
gs.info(requestItem.number);

}
}

Regards
Harish

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

are you saying you have requested_for field's value or requested_for is a variable?

if field then use this; requested_for is a field on REQ and not on RITM

var found = false;
var number;
var Item = new GlideRecord('sc_req_item');
requestItem.addQuery('request.requested_for', 'user sysid');
requestItem.addQuery('cat_item', 'catalog item sys id');
requestItem.query();
while(requestItem.next()){
	//if RITM exist need to something here
	if(requestItem.variables.variableName == 'variable value'){
		found = true;
		number = requestItem.number;
		break;
	}
}

if(number){
	gs.info("RITM found" + number);
}

Regards
Ankur

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

HI @Ankur Bawiskar 

I have seen another tread replied by you.  in that you have mentioned General Approach: 

Could you please help to use the General Approach When we have the variable value's having 2 sysid's and we need to search for only one sys id.

As i checked the general approach was working  only when we search for text value not the list collector variable values.

https://community.servicenow.com/community?id=community_question&sys_id=03a841ebdbd024109e691ea66896197e

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

Hi @Ankur Bawiskar , Thanks it helped.

I have used the generic approach, From below query and used this query in encodedquery.

var encodedQry = 'variables.variablesys_idLIKE' + Value + ' '; //Value will hold the sysid which i am looking for.