- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2020 12:21 AM
Hi,
In our Group Creation SC form, we have a "Group Member" List Collector1 variable(variable attribute: glide_list reference: user table) where user manually select the users from the list. OnSubmit or Onchange of Catalog, we need to identify which of these users already has an existing role and move those users with no roles to another List Collector2 with same attribute as the first (variable attribute: glide_list reference: user table) to separate them and to make the referencing easier in the Workflow approval process.
List Collector 1 Variable - users input all members (with and without role)
List Collector 2 (Hidden in the form)- This needs to populate with users from List Collector 1 with no ITIL role
List Collector 3 (Hidden in the form)- This needs to populate with users from List Collector 1 with ITIL role
I initially created an Onchange Client Script and Script include for same requirement before to identify if user already has an ITIL role but field is only a reference and no population required, List collectors seem to be complex.
Any help will be very much appreciated. Thank you!
Solved! Go to Solution.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2020 06:26 PM
Hi This can be done if you need to split the users into individual variables. If you're using a dedicated workflow for this item, you could just use a script action that runs through the variable and itterates over the values and then stores the values in two arrays on the workflow scratchpad?
Using an onChange script will be invoked every time a user is added.
var CatUtils = Class.create();
CatUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isLicensed: function(){
var answer = false;
var user = new GlideRecord('sys_user_has_role');
user.addQuery('user' , this.getParameter('sysparm_user'));
user.addQuery('role', '282bf1fac6112285017366cb5f867469'); //ITIL Role
user.query();
if(user.hasNext()){
answer = true;
}
return answer;
},
type: 'CatUtils'
});
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('CatUtils');
ga.addParam('sysparm_name','isLicensed');
ga.addParam('sysparm_user',newValue);
ga.getXMLAnswer(response);
function response(answer){
try{
if(answer == 'true'){
addUser(newValue,"license");
} else{
addUser(newValue,"unlicense");
}
g_form.setValue('users','');
}catch(e){
}
}
function addUser(value,list){
var vals = g_form.getValue(list);
if(vals.indexOf(",") > -1 || vals != ''){
vals += "," + value
} else{
vals = value;
}
g_form.setValue(list,vals);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2020 11:35 PM
Hi,
License and Unlicense refers to which table?
sys_user?
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
10-22-2020 11:36 PM
Yes, it is referenced to Sys_user table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2020 11:48 PM
Hi,
So if the user from users variable is having ITIL role then you need to set those users to License variable
Ideally you should set only those users to License which are having ITIL so update script as below
var CatUtils = Class.create();
CatUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isLicensed: function(){
var arr = [];
var user = new GlideRecord('sys_user_has_role');
user.addQuery('user', 'IN' , this.getParameter('sysparm_user'));
user.addQuery('role', '282bf1fac6112285017366cb5f867469'); //ITIL Role
user.query();
while(user.next()){
arr.push(user.sys_id.toString());
}
return arr;
},
type: 'CatUtils'
});
Updated client script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('CatUtils');
ga.addParam('sysparm_name','isLicensed');
ga.addParam('sysparm_user',newValue);
ga.getXMLAnswer(response);
function response(answer){
try{
if(answer != ''){
addUser(answer,"license");
} else{
addUser(newValue,"unlicense");
}
g_form.setValue('users','');
}catch(e){
}
}
function addUser(value,list){
var vals = g_form.getValue(list);
if(vals.indexOf(",") > -1 || vals != ''){
vals += "," + value;
} else{
vals = value;
}
g_form.setValue(list,vals.toString());
}
}
if this setup is in your personal instance and you are ok to share url and some admin credentials then share here ankurb.snow@gmail.com
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
10-23-2020 12:13 AM
Thanks again, Ankur.
The requirement we have is in List Collector 1 (all group members are inputted), separate users with ITIL role (List Collector 2)and No ITIL role (List Collector 3), then in Workflow, use the values in
List Collector 2 to automatically add the users
List Collector 3 to generate manager approval for each of the users without the license.
I apologize for not stating the detailed requirement
That is why i am hoping to populate in a list collector as well those who do not have the ITIL roles so we can just use this as reference in WF, notification, Multi-row variable set
I appreciate your time looking into this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2020 12:41 AM
Hi,
If this is just to filter users for approval etc then no need of extra variables
you can use scripting to handle this with just 1 list collector variable
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader