Assignment group variable shoud display only groups which the user belongs to ?

raj99918
Tera Contributor

Hi team,

 

I have catalog form having Group variable (which contains few groups called Group1,Group2,Group3,Group4,Group5,Group6) if the Requsted user is member of only these 3 groups like (Group1,Group2 and Group3) then it should display only 3 groups called (Group1,Group2 and Group3) in Group variable How can I achieve this ?

 

Thanks.

7 REPLIES 7

Hi @raj99918,

The filter is in last few lines of the client script. 

 

If you found my reply helpful, please mark it as helpful.

 

Thanks and Regards,

Ehab

Not applicable

Hi @raj99918 ,

Apologies. I think i pasted the same code earlier.

 

Can you please try the below code once again-

function onLoad() {
    var assignmentGroupField = 'assignment_group';

    // GlideAjax call to get the user's groups
    var ga = new GlideAjax('AssignmentGroupAjax');
    ga.addParam('sysparm_name', 'getUserGroups');
    ga.getXMLAnswer(function(response) {
        var groupSysIds = response.split(',');
        var filter = 'sys_idIN' + groupSysIds.join(',');

        // Set the filter on the assignment group field
        g_form.setReferenceFilter(assignmentGroupField, filter);
    });
}

 

Script Include- 

var AssignmentGroupAjax = Class.create();
AssignmentGroupAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getUserGroups: function() {
        var userGroups = [];
        var userId = gs.getUserID();
        var gr = new GlideRecord('sys_user_grmember');
        gr.addQuery('user', userId);
        gr.query();
        while (gr.next()) {
            userGroups.push(gr.group.sys_id.toString());
        }
        return userGroups.join(',');
    }
});

 

If my response has resolved your query, please consider giving it a thumbs up ‌‌ and marking it as the correct answer‌‌!


Thanks & Regards,

Sanjay Kumar

Hi @Community Alums 

 

g_form.setReferenceFilter(assignmentGroupField, filter);

 

This line throwing an error as part of DOM object is there any other way to set the Reference variable ?