on submit catalog checking current user is part of group or not is not working

keshav77
Tera Contributor

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-- 

keshav77_0-1748685018361.png

and here is my client script--

keshav77_1-1748685084331.png

 

1 REPLY 1

J Siva
Tera Sage

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:

  1. Create a hidden field to store the sys_ids of the groups the opened_by user belongs to.

  2. Populate the group sys_ids using an AJAX call.

  3. Use the hidden field value in the reference qualifier of the Group field.


Catalog Variables:

JSiva_0-1748768171172.png

Ref Qualifier:

JSiva_1-1748768215941.png

javascript:"sys_idIN"+current.variables.group_sys_ids

 

On Change catalog client script:

JSiva_2-1748768291000.png

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:

JSiva_3-1748768641865.png

 

 

 

Regards,
Siva