on submit catalog checking current user is part of group or not is not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2025 02:51 AM
Hi All,
I am working on one catalog where opened by and assignment group is mandatory where we need to check if user(opened by) is part of group or not if not not allow to submit the catalog. I have written script include and client script but it is not working for me kindly assist me with this.
here is my script include--
and here is my client script--
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2025 02:04 AM
Hi @keshav77
Instead of validating whether the user belongs to a selected group, you can display only the groups where the opened_by user is a member. This ensures that the user can select only from groups they are part of.
Try the following approach:
Create a hidden field to store the sys_ids of the groups the opened_by user belongs to.
Populate the group sys_ids using an AJAX call.
Use the hidden field value in the reference qualifier of the Group field.
Catalog Variables:
Ref Qualifier:
javascript:"sys_idIN"+current.variables.group_sys_ids
On Change catalog client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var script = new GlideAjax('CatalogUtlis');
script.addParam('sysparm_name', 'getGroups');
script.addParam('sysparm_user', g_form.getValue('opened_by'));
script.getXMLAnswer(result);
}
function result(answer) {
g_form.setValue('group_sys_ids', answer);
}
Client callable script include:
getGroups: function() {
var group_id = [];
var user_id = this.getParameter('sysparm_user');
var grp_member = new GlideRecord('sys_user_grmember');
grp_member.addQuery('user.sys_id', user_id);
grp_member.query();
while (grp_member.next()) {
group_id.push(grp_member.group.sys_id);
}
return group_id.toString();
},
Output:
Regards,
Siva