If "ALL or N/A" is selected don’t allow any other selections.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2025 04:26 AM
Hello Everyone,
I have one requirement related to the catalog item. In my catalog item there is a one list collector.
REQ : If "ALL or N/A" is selected don’t allow any other selections in list collector.
Table - Sys_user table
Here multiple values in list collector like ALL, NA, AB, BC, DE, FG...etc.
Whenever they are trying to select All or N/A then don't allow other selection.
How many we have like ui policy, script include and client scripts which way it is easy to solve the issue.
Regards,
Madhav.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2025 11:15 AM
Please use this:
1. onChange client script for "user_list"
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) return;
var selected = g_form.getValue('user_list'); // Comma-separated sys_ids
var selectedNames = [];
// Convert to array of sys_ids
var selectedSysIds = selected.split(',');
// Create GlideAjax call to resolve names of selected users
var ga = new GlideAjax('GetUserNamesForSysIds');
ga.addParam('sysparm_name', 'getNames');
ga.addParam('sysparm_ids', selectedSysIds.join(','));
ga.getXMLAnswer(function(response) {
selectedNames = response.split(',');
// Check if ALL or N/A is selected along with others
var hasAllOrNA = selectedNames.includes('ALL') || selectedNames.includes('N/A');
if (hasAllOrNA && selectedNames.length > 1) {
g_form.clearValue('user_list');
g_form.showFieldMsg('user_list', 'You cannot select other users along with "ALL" or "N/A". Please choose only one.', 'error');
}
});
}
2. Script include: (GetUserNamesForSysIds)
var GetUserNamesForSysIds = Class.create();
GetUserNamesForSysIds.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getNames: function() {
var ids = this.getParameter('sysparm_ids').split(',');
var names = [];
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', 'IN', ids);
gr.query();
while (gr.next()) {
names.push(gr.name.toString());
}
return names.join(',');
}
});