- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi,
I’m working on a catalog item where I need to configure two fields with the below behavior:
Field Name: Roles assigned to the user
Requirement: It should show the list of all roles assigned to the logged-in user(Requested for) field, basically fetched from the sys_user_has_role table.
Field Name: Groups associated with the selected role
Type: Multi-select dropdown
Requirement:
When a role is selected in the “Roles assigned to user” field,
the system should display all groups associated with that role (in which the user is a member).
All those groups should be auto-selected by default, but the user should be able to deselect if needed.
I’m trying to implement this logic using a catalog client script and script include, but I’m not sure about the best approach to dynamically populate the multi-select dropdown based on the selected role.
Has anyone implemented something similar or can guide on the right way to achieve this (preferably without using gel or DOM methods)?
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Ensure the default value for requested_for has gs.getUserID() so that logic works when form loads for logged in user and then it will work based on user change
if you want based on requested for variable and user will select that then do this
javascript: var query;
var cu = gs.getUser().getUserByID(current.variables.requested_for);
query = 'nameIN' + new global.ArrayUtil().convertArray(cu.getRoles());
query;
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Ideally you should do this
1) 1st variable point to sys_user_role table with advanced ref qualifier as this
javascript: var query;
var cu = gs.getUser();
query = 'nameIN' + new global.ArrayUtil().convertArray(cu.getRoles());
query;
2) 2nd variable point to sys_user_group, list collector type
refer my blog on how to set list collector based onchange + GlideAjax
Dynamically set list collector on change of variable
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hope you are doing good.
Did my reply answer your question?
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Ankur Bawiskar ,
Thanks for your response.
The code is working fine for current logged-in user, but my requirement is to fetch the roles based on the user selected in the 'Requested for' variable instead of logged-in user.
Could you please suggest?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Glad to know that my script worked for you.
you required logged in user as per your original requirement
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
