- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2021 02:17 AM
Hi All!
I'm currently building a catalog item for a request to remove user from groups. There is firstly a user field from sys_user table and then groups field. What I'm trying to do is to link these 2 fields so when the user is selected, in the groups field would appear only the groups that this particular user is part of. Yet no success. Any ideas?
Thank you in advance.
Best regards,
Oleg.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2021 02:28 AM
Hi,
You will have to create reference qualifier for the 2nd variable and call script include function
how to call script include in 2nd variable
javascript: 'sys_idIN' + new GetGroupMembers().getGroups(current.variables.userVariableName);
Script Include:
var GetGroupMembers = Class.create();
GetGroupMembers.prototype = {
initialize: function() {
},
getGroups:function(user) {
var group_array = [];
var getMembers = new GlideRecord('sys_user_grmember');
getMembers.addQuery('user ',user);
getMembers.query();
while(getMembers.next())
{
var groupSysId = getMembers.getValue('group');
group_array.push(groupSysId);
}
return group_array;
},
type: 'GetGroupMembers'
};
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
‎03-10-2021 02:28 AM
Hi,
You will have to create reference qualifier for the 2nd variable and call script include function
how to call script include in 2nd variable
javascript: 'sys_idIN' + new GetGroupMembers().getGroups(current.variables.userVariableName);
Script Include:
var GetGroupMembers = Class.create();
GetGroupMembers.prototype = {
initialize: function() {
},
getGroups:function(user) {
var group_array = [];
var getMembers = new GlideRecord('sys_user_grmember');
getMembers.addQuery('user ',user);
getMembers.query();
while(getMembers.next())
{
var groupSysId = getMembers.getValue('group');
group_array.push(groupSysId);
}
return group_array;
},
type: 'GetGroupMembers'
};
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
‎03-15-2021 01:48 AM
Hello Ankur,
Thank you very much! It works.
Best regards,
Oleg.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2021 01:54 AM
Glad to help.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-13-2021 02:56 AM
Hi Ankur,
We exactly have the same requirement to populate groups based on the user variable on the catalog form. We follow the above same steps in Quebec release and it is not working. Can you please suggest?
Regards
Muktha