- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2023 03:11 AM - edited 02-16-2023 03:33 AM
Hello everyone
I have one field populated with the department of the logged in user and I have another List collector field with all users.
I would like to know how I can do the following. If I manually change the department, in the other users field I just want to be shown to choose users that belong to the department I indicate in the other field.
Thanks in advance
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2023 04:10 AM
Also If you only want to display users from Department to be populated then there is no need to write script include also.
You just need to update reference qualifier on User Variable
javascript: "department.sys_idIN" + current.variables.department
you can replace 'current.variables.<with your variable name>'
Hope this will work for you...!!
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2023 03:47 AM
As per my understanding you want to populate group values or group members based on select group, if yes you can refer following links to resolve your issue.
Thank you
Rajesh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2023 04:18 AM - edited 02-15-2023 04:44 AM
Hello @MARISA INACIO1
You can write a client callable script include to get sys ids of group members and call that script include in reference qualifier of User field.
Step 1: Create Client callable script include and write below function in it
Script include Name : getUserUtils
client callable : yes
getUsersList: function(groups) {
var groupMembers;
var grGrpMem = new GlideRecord("sys_user_grmember");
grGrpMem.addEncodedQuery('group.sys_idIN' + groups);
grGrpMem.query();
while (grGrpMem.next()) {
groupMembers = groupMembers +','+ grGrpMem.getValue('user').toString();
}
//gs.log('getUserUtils=' + "sys_idIN" + groupMembers );
return "sys_idIN" + groupMembers;
},
Step 2 : call that script include function in reference qualifier of User field
Reference qualifier - javascript: new getUserUtils().getUsersList(current.variables.groups);
Here you can use, current.variables.<name of your variable>
and If you want to display user's depending upon department field just change the reference qualifier
javascript:
var query = new getUserUtils().getUsersList(current.variables.groups);
query = query + "^department=" + current.variables.department;
query;
so that user's from specific department will be available.
Here is the output :
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2023 03:17 AM
Thanks for the great explanation.
I'm trying to adapt it because what I want is that deep inside the department that I choose (variable department), only the users of that department appear, and it's not working. I put the cmn_department table but could you help me adjust the rest of the script to this table?
Thanks again
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2023 03:45 AM - edited 02-16-2023 03:45 AM
@MARISA INACIO1 Sure
If possible can you please share your code please ?
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates