- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2025 10:28 AM
Hello,
At a high level I want to accomplish the following:
- User opens Catalog Item "A"
- User answers a precursor question with "No"
- Client script checks if "Requested For" user can access Catalog Item "B" using the "Available For" criteria
- If yes, redirect to Catalog Item "B"
- If not, return none.
So far I have worked out how to follow the table breadcrumbs to the individual user criteria records for Catalog Item "B".
Is there a quick and easy way to check a user against those records to see if they fit conditions, or do I need to pull in all the user data and check each criteria individually (e.g. role, groups, company, etc)?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2025 11:12 PM
Hi @LilithP ,
1. create a client callable script include
name: userCriteriaCheckAjax
script
var userCriteriaCheckAjax = Class.create();
userCriteriaCheckAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkUserWithUC: function() {
var userID = this.getParameter('sysparm_userid') ? this.getParameter('sysparm_userid') : gs.getUserID();
var userCriteria = [];
var catm2mgr = new GlideRecord('sc_cat_item_user_criteria_mtom');
catm2mgr.addEncodedQuery('sc_cat_item=' + this.getParameter('sysparm_catid'));
catm2mgr.query();
while (catm2mgr.next()) {
userCriteria.push(catm2mgr.getValue('user_criteria'));
}
return sn_uc.UserCriteriaLoader.userMatches(userID, userCriteria);
},
type: 'userCriteriaCheckAjax'
});
adjust you client script like this
adjust 10th line by adding your catalog item sysid (the one which your want to check the user criteria against)
I have added an alert for quick chek if this work you can redirect the user to desired catalog item location
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '' || newValue == 'yes') {
return;
}
var requestedForId = g_form.getValue('requested_for');
var ga = new GlideAjax('global.userCriteriaCheckAjax');
ga.addParam('sysparm_name', 'checkUserWithUC');
ga.addParam('sysparm_userid', requestedForId);
ga.addParam('sysparm_catid', 'put your catalog item sysid here'); // replace with your target catalog item which you wanted to route to
ga.getXMLAnswer(function(answer) {
var isEligible = (answer === 'true');
alert('User eligibility:', isEligible);
//add your routing logic here
//g_navigation.open('com.glideapp.servicecatalog_cat_item_view.do?v=1&sysparm_id=01243276837e2210a2dfb5b6feaad333','blank'); you can use this kin of line for redirection of user by replacing the sysid in the url
});
}
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2025 05:59 AM
Thank you! Yes, I missed the client callable script part, it is working now.