Check User is member of one of the selected groups in the catalog form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-11-2024 03:00 AM
Hello all,
There are two variables in the form called requested for, groups. This form is to assign the requested for to those groups. I created one onsubmit client script and script include to check whether the requested for user is already a member of any of the selected groups. if yes it need to show an error stating that the user is already the member of specific group.
I written the following , but it was not working. Could anyone help me to fix it.
thanks,
//client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-11-2024 03:32 AM
Hi @Aravindk5919,
I like to know if that call to the script include is made, is here the problem? Another question, the user of catalog form should have the necessary rights to call the script include?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-11-2024 04:35 AM
Good job adding the logs. Which ones are you seeing? The value from the groups list collector is a comma-separated list of sys_ids, and that's what you want for the addQuery, so don't split the parameter script variable first and use it in the addQuery
gr.addQuery('group', 'IN', groupsString);
beyond this, if you want the alert to include every group which the user is already a member of you would want to return all of the records using while (gr.next()) in place of if (gr.next()) then push the group name or whatever to an array and use this list of names in the alert. And you can dot-walk instead of doing another GR
var result = [];
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', userSysId);
gr.addQuery('group', 'IN', groupsString);
gr.query();
while (gr.next()) {
gs.log("CheckUserGroupMembership inside if","AK");
result.push(gr.group.name);
}
...
return result.join(', ');