reference qualifier to show only wanted groups

Jori
Giga Guru

I created a form to show only specific groups using reference qualifiers to add/remove users from aad groups.
form and flow works fine, but when im using the form to select groups, is it possibly to only get the groups the user is not member of when adding and when removing only the groups the user is member of?

1 ACCEPTED SOLUTION

Tai Vu
Kilo Patron
Kilo Patron

Hi @Jori 

Let's try the below approach in the Reference Qualifier of your Group variables.

TaiVu_0-1699516195027.png

 

Cheers,
Tai Vu

 

 

View solution in original post

14 REPLIES 14

Work perfectly! Thank you 

jakeb25
Tera Contributor

Hello! this works great for the current logged in user, but is there a way to modify this script where it would show only the groups that the current user record being viewed is a member of?

Hi @jakeb25 

Yes that's exactly the above query from my screenshot.

sys_idINjavascript:gs.getUser().getMyGroups();

 

Cheers,

Tai Vu

jakeb25
Tera Contributor

Thanks for the swift response! Unfortunately, that does not work for our use case because the getMyGroups function still only pulls in the groups of the currently logged in user, we're looking for the groups that the user record we are looking at is a member of, so we did get there but had to use this script include:

 

var UserRefQual = Class.create();
UserRefQual.prototype = {
    initialize: function() {},
    getGroups: function(user) {
        var groups = []; //Creates an empty list (array) named groups. This will later hold the IDs of the groups that the user belongs to.

        var grUserGrp = new GlideRecord('sys_user_grmember');
        grUserGrp.addQuery('user', user.sys_id); //Adds a condition to the search prepared above, telling it to only look for records where the user field matches the sys_id of the user we're interested in. It's like saying "in that list, only show me the memberships for this specific user."
        grUserGrp.query();

        while (grUserGrp.next())
        {
            groups.push(grUserGrp.group.toString()); //This loop goes through each record found by our search. For each record, it takes the group's ID (grUserGrp.group.toString()) and adds it to our groups list. It's like saying "for each group this user belongs to, add the group's ID to our list."
        }
        gs.info("sys_idIN" + groups);
        return "sys_idIN" + groups;
    },
    type: 'UserRefQual'
};

Hi @jakeb25 

I see. So the case is that we wanna retrieve the groups associated with a specific user input.

Your getGroups function appears to be in good shape. Simply invoke it within the Reference Qual and it should do the trick.

javascript&colon;new UserRefQual().getGroups(current.variables.<your_user_reference_variable_name>);

 

Cheers,

Tai Vu