Needs to populate only the Groups which Requested For field User ID is not added

Arjun Reddy Yer
Tera Guru

Can you please help me @Vasantharajan N 

 

As need to populate only the Active Groups and the Groups which the Requested For field User ID is not added.

As off now created the below script, but it's working based on the User who is raising the request form and it's showing only the Active Groups which is fine.

As it should work based on the Requested For field User ID.

ArjunReddyYer_0-1706152825168.png

 

4 REPLIES 4

Amit Verma
Kilo Patron
Kilo Patron

Hi @Arjun Reddy Yer 

 

You need to make a client callable script include through which you can query the sys_user_grmember table to get the list of groups for which the requested_for is not a member of and then call the script include from your reference qualifier.

 

Please refer below posts which will help you to do the configuration :

https://www.servicenow.com/community/developer-forum/get-user-groups-list-from-requested-for/td-p/27...

https://www.servicenow.com/community/itsm-forum/get-all-groups-user-is-a-member-of-based-off-of-a-ca...

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

Sandeep Rajput
Tera Patron
Tera Patron

@Arjun Reddy Yer Unfortunately, getMyGroups is only available for logged in user, since you would like to get the groups for requested for, you need to write a script include method, query Group Member table to get the groups of the requested for user.

 

Let me know in case you need help on the scripting part.

Vasantharajan N
Giga Sage
Giga Sage

@Arjun Reddy Yer 

 

Step 1: Update your advanced reference qualifier to javascript:"active=true^sys_idNOT IN"+new ScriptIncludeName().getGroupMemberOf(current);

Make sure you replace your script include name where you will have the logic defined in step 2 given below.

 

Step 2:  Define function to return the list of groups the user is member of.

 

getGroupMemberOf: function(currentRec) {
        var groupList = gs.getUser().getUserByID(currentRec.variables.requested_for.toString()).getMyGroups();
        var sysIds = [];
		for(var i = 0; i < groupList.size(); i++) {
             sysIds.push(groupList.get(i).toString());
        }
        return sysIds.join();
    }

 

Step 3: Test the functionality


Thanks & Regards,
Vasanth

Sandeep Rajput
Tera Patron
Tera Patron

@Arjun Reddy Yer You can also try the following if you do not wish to use script include.

 

Screenshot 2024-01-25 at 5.30.46 PM.png