Show Group members based on On Change of choices from other variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2024 09:25 PM
Hello Everyone,
I am trying to auto populate group members in a variable based on other variable choices.
EX: We have 2 variable V1 and V2
V1 has 3 choices
Choices: TYPE1, TYPE2, TYPE3
When V1 is selected as = TYPE1
the Variable V2 should show list group members who are part of "TYPE1Group"
When V1 is selected as = TYPE2
the Variable V2 should show list group members who are part of "TYPE2Group"
When V1 is selected as = TYPE3
the Variable V2 should show list group members who are part of "TYPE3Group"
Please help me with this functionality.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2024 09:34 PM - edited 04-03-2024 09:48 PM
@Insider Please refer the below link for your requirement.
Alternatively you can even pass the variable V1 inside the function as below on the V2 variable as reference qualifier using User table,
javascript : new <Script Include>.<function name>(current.variables.requested_for);
Please Note: It's not a best practice to use "GlideRecord" in client scripts directly. You must go with GlideAjax only.
Please mark this as helpful and accept it as a solution if this resolves your query.
Thanks,
Sujatha V.M.
Sujatha V.M.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2024 01:52 AM
Hello,
V1 and V2 are not dependent.
they are independent variables.
V1 is a select box with choices.
V2 refers to Group table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2024 09:42 PM
Hi @Insider
As per your requirement, you need to Create New- onChange Catalog Client Script
1. Type-> onChange
2. Variable-> V1
Script:
var groupName = newValue + "Group"; // Constructs the group name based on the selection, e.g., “TYPE1Group”
// Clear previous options
g_form.clearOptions('V2');
// Query to get the sys_id of the group
var groupIdQuery = new GlideRecord('sys_user_group');
groupIdQuery.addQuery('name', groupName);
groupIdQuery.query();
if (groupIdQuery.next()) {
var groupId = groupIdQuery.sys_id;
// Now, get the group members
var memberQuery = new GlideRecord('sys_user_grmember');
memberQuery.addQuery('group', groupId);
memberQuery.query();
while (memberQuery.next()) {
var userId = memberQuery.user;
// Get user details
var userRec = new GlideRecord('sys_user');
if (userRec.get(userId)) {
var userName = userRec.name;
var userSysId = userRec.sys_id.toString();
// Add this user as an option to V2
g_form.addOption('V2', userSysId, userName);
}
}
}
Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning
Thanks & Regards
Deepak Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2024 01:54 AM
Hello Deepak,
V1 and V2 are not dependent.
they are independent variables.
V1 is a select box with choices like Type, Change and etc...
V2 refers to Group table.