How to Restrict users for List collector?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2022 11:43 PM
Hi all,
In my catalog item i have 2 variables
variable 1 - select matter: refers to u_matter table
variable 2 - folder permission (type-list collector)- refers to user table
i have a table(matter details) in my instance with following details
My requirement is
1.If i select matter 12345 in variable 1 it should check if matter have timekeeper number in matter details table, if so timekeeper number available for the selected matter those timekeepr users should be hidden in variable 2(list collector) when type is exclusion.
2.If i select matter 12345 in variable 1 it should check if matter have timekeeper number in matter details table, if so timekeeper number available for the selected matter those timekeepr users should only visibile in variable 2(needed only inclusion users) when type is inclusion.
note : 1.we have time keeper number in user table.
2.we have relation between u_matter table and matter details table.(matter)
3.we have relation between matter details table and user table( timekeeper )
How can i achieve this via using onChange scripts

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2022 01:07 AM
Hi Mitra,
you don't necessary need to use an onChange script.
I see a solution here if you create a script include that provide you a list of sysIDs that match your condition and you can select from them, then you define a reference qualifier on your variable 2.
Can you provide more details about the scenario?
a. You don't care about users not listed in matter details table at all?
b. What if the user is (e.g. by mistake) defined in both, exclusion and inclusion - what has a preference?
So basically my question is, what would be the proper condition is this
1. All users except users in exception defined in matter details table?
2. Only users in matter details table that are in inclusion but not in exclusions?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2022 06:01 AM
Hi Jan,
Here my requirement is 3 scenarios
1.If users are in Inclusion then only those users should be visible in list collector.
2.If Users are in Exclusion then those users should not be in lists
3.If not both then all users should be visible.
Inclusion or exclusion can be empty
There will be different matter numbers with inclusion /exclusion users with record present in common table (matter details)
Based on matter number folder permissions should be visible / hiddden in variable 2 list collector field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2022 08:43 AM
Hi Mitra,
so what you need to do ideally is to
1. Create script include with a function that will accept the argument from variable1
2. Define one array Inclusions, another array Exclusion
3. Glide record that lists all records of matter details table referring to this particular variable1 value
4. In a while loop - if the type is inclusion, glide record query to sys_user table to search for user with particular timekeeper code, add this user to Inclusion array, if the type is exclusion glide record to sys_user and add this user to Exclusion array
5. When the while ends, define a 3rd array and do a difference between these two arrays (there is a build in function in ServiceNow (check script include ArrayUtil, function diff), that would be something like
var result = new ArrayUtil();
var resultArray = result.diff(InclusionArray,ExclusionArray));
now you have an array of users that are in inclusion but never in exclusion
the script include will return a string...
return 'sys_idIN' + resultArray.join();
And then you call then script include in the field reference qualifier of the 2nd variable (that one points to sys_user table).
Example:
Variable in catalog item
Script include
(I have just a simple hardcoded function for testing, but your logic I described above would need to be in the script include function)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2022 10:29 PM
Hi Jan ,
Can you help me on this?
Script include :
getUserRestrictDetails: function() {
var permissionUsers = '';
var client = '';
var matter = '';
if (this.getParameter('sysparm_matter')) {
matter = this.getParameter('sysparm_matter');
} else {
matter = "undefined";
}
if (this.getParameter('sysparm_client')) {
client = this.getParameter('sysparm_client');
} else {
client = "undefined";
}
var permission = this.getParameter('sysparm_userName');
var gr = new GlideRecord('x_zoc_co_file_co_file_ethical_walls');
gr.addEncodedQuery("matter=" + matter + "^ORclient=" + client);
gr.query();
if (gr.next()) {
while (gr.type == 'inclusion') {
permissionUsers = gr.timekeepers;
}
while (gr.type == 'exclusion') {
var user = [];
var valuesFromForm = gr.timekeepers.getDisplayValue();
var per = permission.split(",");
for (var i = 0; i < per.length; i++) {
var gb = new GlideRecord('sys_user');
gb.addQuery("sys_id", per[i]);
gb.query();
if (gb.next()) {
if (valuesFromForm.indexOf(gb.u_timekeeper_id) == -1) {
user.push(gb.u_timekeeper_id);
}
}
permissionUsers = user.join(",");
}
}
} else {
permissionUsers = user;
}
var finalUsers = permissionUsers.split(",");
var users = [];
for (var a = 0; a < finalUsers.length; a++) {
var gc = new GlideRecord('sys_user');
//gc.addQuery("u_timekeeper_id",finalUsers[a]);
gc.addEncodedQuery("u_timekeeper_id!=NULL^u_timekeeper_id=" + finalUsers[a]);
gc.query();
if (gc.next()) {
users.push(gc.sys_id);
}
}
var answer = users.join(",");
return answer;
},
Onchange Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var gr = new GlideAjax("permissionChecking");
gr.addParam('sysparm_name', 'getUserRestrictDetails');
gr.addParam('sysparm_userName', newValue);
gr.addParam("sysparm_matter", g_form.getValue('please_select_a_matter_name_from_the_dropdown'));
gr.addParam("sysparm_client", g_form.getValue('please_select_a_client_name_from_the_dropdown'));
gr.getXML(HelloWorldParse);
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var permission = g_form.getValue('folder_permission');
if (newValue != oldValue) {
if (answer.length == permission.length) {
//
} else {
//alert("some users doesn't have access this folder");
g_form.setValue("folder_permission", answer);
}
}
}
As per your suggestion i have tried but still facing issues and users are getting displayed in 2nd varaible 2 (folder_permission) based on my condition