- 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
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);
}
}
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2022 10:30 PM
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
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-28-2022 02:38 AM
HI
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
- 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-29-2022 03:24 AM
Hi
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.