Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

list collector variable to show only group the user is member of + filter out some groups

flsn2
Tera Expert

Hi 

 

I'm trying to create a catalog item so that itil user could choose user's / groups with who they want to share a specific report.

 

So i'm stuck with the group portion.

 

I did create a list collector with sys_user_group table.

 

With this reference qualifier that i found on the community

 

javascript:'sys_idIN'+gs.getUser().getMyGroups()

 

This code is working but the issue i got is that from the list collector some groups should not be visible.

 

Is there a way to filter out some groups ?

 

flsn2_0-1715279752878.png

 

 

 

 

2 ACCEPTED SOLUTIONS

swathisarang98
Giga Sage

Hi @flsn2 ,

 

There is no direct way to show logged in user group and filter out some group, inorder to achieve this you have to create a script include and call that in your reference qualifier.

 

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

Regards,

Swathi Sarang

View solution in original post

@flsn2 ,

 

Please find the working example,

Reference qualifier,

swathisarang98_0-1715287639386.png

Script include:

swathisarang98_1-1715287663192.png

Code:

 

var getMyGroupList = Class.create();
getMyGroupList.prototype = {
    initialize: function() {},
    getGrouplist: function() {
		var sysId = gs.getUserID();
		//gs.info('sys id ' + sysId);
        var gr = new GlideRecord('sys_user_grmember');
        gr.addQuery('user', sysId);
		gr.addEncodedQuery('group!=287ee6fea9fe198100ada7950d0b1b73^ORgroup=NULL'); //added encoded query that group is not DATABASE
        gr.query();
        var arr = [];
        while (gr.next()) {
			arr.push(gr.getValue('group'));
        }
		//gs.info('array ' + arr);
		return 'sys_idIN'+arr.toString();


    },
    type: 'getMyGroupList'
};

 

 Result:

I had 4 group ,

swathisarang98_2-1715287759035.png

swathisarang98_3-1715287782687.png

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

Regards,

Swathi Sarang

 

 

 

View solution in original post

2 REPLIES 2

swathisarang98
Giga Sage

Hi @flsn2 ,

 

There is no direct way to show logged in user group and filter out some group, inorder to achieve this you have to create a script include and call that in your reference qualifier.

 

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

Regards,

Swathi Sarang

@flsn2 ,

 

Please find the working example,

Reference qualifier,

swathisarang98_0-1715287639386.png

Script include:

swathisarang98_1-1715287663192.png

Code:

 

var getMyGroupList = Class.create();
getMyGroupList.prototype = {
    initialize: function() {},
    getGrouplist: function() {
		var sysId = gs.getUserID();
		//gs.info('sys id ' + sysId);
        var gr = new GlideRecord('sys_user_grmember');
        gr.addQuery('user', sysId);
		gr.addEncodedQuery('group!=287ee6fea9fe198100ada7950d0b1b73^ORgroup=NULL'); //added encoded query that group is not DATABASE
        gr.query();
        var arr = [];
        while (gr.next()) {
			arr.push(gr.getValue('group'));
        }
		//gs.info('array ' + arr);
		return 'sys_idIN'+arr.toString();


    },
    type: 'getMyGroupList'
};

 

 Result:

I had 4 group ,

swathisarang98_2-1715287759035.png

swathisarang98_3-1715287782687.png

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

Regards,

Swathi Sarang