logo

NJP

Apply user criteria to another user in a reference qualifier

Import · Jul 03, 2019 · article

I recently came across a requirement from a customer for limiting the available request items for selection when transferring a call to a request based what items the caller populated in the caller field had access to.

This meant applying user criteria to the user populated on the record rather than the logged in user in the 'Request Item' reference qualifier.

In order to achieve this I utilised the User Criteria Scoped API

https://developer.servicenow.com/app.do#!/api%5Fdoc?v=madrid&id=UCLS-getAllUserCriteria

Along with a script include + reference qualifier combo

https://www.servicenowguru.com/scripting/script-includes-scripting/advanced-reference-qualifier-scri...

Finished script below:

function call_req_items(){

var allowedItems = '';
var caller = current.caller.sys_id; //the user populated in the call 
var result = new sn_uc.UserCriteriaLoader.getAllUserCriteria(caller);

for(var i = 0; i < result.length; i++){

var reqItems = new GlideRecord('sc_cat_item_user_criteria_mtom');
reqItems.addQuery('user_criteria', result);
reqItems.query();
while (reqItems.next()){
allowedItems += (',' +reqItems.sc_cat_item.sys_id);
}
return 'sys_idIN' + allowedItems;
}

} 

Important.

The plugin User Criteria Scoped API plugin must be activated for this to work

View original source

https://www.servicenow.com/community/itsm-articles/apply-user-criteria-to-another-user-in-a-reference-qualifier/ta-p/2312781