Restricting Assignment Group choices based on logged in user

Madhan007
Tera Contributor

Hello all,
I have an Assignment Group Field referencing to Group (sys_user_group) table . But I want to display only the groups that Requester is part of.

And if the Requester is part of only one group, it has to be Auto populated. 
How can i achieve it ? please pour your insights.

Thanks in advance

1 ACCEPTED SOLUTION

Hi @Madhan007 ,

 

You cant call both function in single reference qualifier and you wanted to auto populate the Group if user has single group so you have to call it in default value of the same field  otherwise autopopulate will not work .

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

View solution in original post

7 REPLIES 7

Jean-Emmanuel
Tera Guru

Hello @Madhan007 ,

First of all, you have to define a reference qualifier in order to limit the list of group available 
Concerning the auto-population, a client script should get the job done..

If you need more details about how to perform any of these task, feel free to let me know so that i provide some samples scripts for you..

**Please mark my answer helpful or correct if it applies. 

 

Thank you!
JE



Hi @Jean-Emmanuel , Thanks for the reply.

It would help me a lot if you could provide some sample scripts

 

Thank you!

Step 1 : Create a script include (which provide all groups for a given user in a reference qualifier format)

 

 

var MyGroupUtils = Class.create();
MyGroupUtils.prototype = {

    getUserGroupRefQual: function(userId) {
        var answer = "";
        var arr = gs.getUser().getUserByID(userId).getMyGroups().toArray();
        var i = 0;
        while (i < arr.length) {
            if (answer == "") {
                answer = arr[i];
            } else {
                answer = answer + "," + arr[i];
            }
		i++;
        }
        return 'sys_idIN' + answer;
    },
    type: 'MyGroupUtils'
};

 

 

Step 2 : Define your reference qualifier on assignment group field (if you are on a extended task table, be sure to edit override setting to avoid apply the logic on all task table)

For the type of the reference qualifier, choose "Advanced" and set the following value 

 

javascript &colon; new MyGroupUtils().getUserGroupRefQual(current.requester-field-name)

 

 



after these steps the values of Assignment group id dynamically updated depending of the requester.

swathisarang98
Giga Sage
Giga Sage

Hi @Madhan007 ,

 

You can write a reference qualifier and script include to achieve this,

 

First if logged in user has more than one group tagged to him 

Reference qualifier(advanced) on field Assignment group

swathisarang98_0-1710361156558.png

 

javascript&colon; new getAllMyGroups().getGroups()

 

 

Second if loggedin user has only one group,

In default value call the script include but second function,

swathisarang98_2-1710361310722.png

 

javascript&colon;new getAllMyGroups().getSingleGroup()

 

 

Script include:

swathisarang98_1-1710361198365.png

 

var getAllMyGroups = Class.create();
getAllMyGroups.prototype = {
    initialize: function() {},

    getGroups: function() {

        var sysId = gs.getUserID();
        var ga = new GlideRecord('sys_user_grmember');
        ga.addQuery('user', sysId);
        ga.query();
        var arr = [];
        while (ga.next()) {
            arr.push(ga.group.toString());
        }
        return 'sys_idIN' + arr.toString();
    },

    getSingleGroup: function() {
        var sys = gs.getUserID();
        var groupName;
        var gr = new GlideRecord('sys_user_grmember');
        gr.addQuery('user', sys);
        gr.query();
        if (gr.getRowCount() == 1) {
            if (gr.next()) {
                groupName = gr.group.toString();
            }
        }
        return groupName.toString();
    },


    type: 'getAllMyGroups'
};

 

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang