i,Dynamic filter with script include

Alon Grod
Tera Expert

Hi, 

Im trying to create a customize dynamic filter using script include that will show only groups that I belongs to without the parents group (the OOB One of my groups dynamic filter includes the parents group).

 

What am I doing wrong?

AlonGrod_0-1765973170141.png 

AlonGrod_1-1765973202207.png

var getMyGroupsOnly = Class.create();
getMyGroupsOnly.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getGroups: function(userId) {
		
		var cr = [];
        var gr = new GlideRecord('sys_user_grmember');
		gr.addQuery('user',userId);
		gr.addQuery('group.active',true);
		gr.query();
		while(gr.next()){
			var groupId = gr.getValue('group');
			if(!gs.nil((groupId))){
				cr.push(groupId);
			}
		}
        return cr;
    },

    type: 'getMyGroupsOnly'
});

 

 

Result:

AlonGrod_2-1765973250739.png

 

 

 

10 REPLIES 10

Ankur Bawiskar
Tera Patron
Tera Patron

@Alon Grod 

did you call that script include from background script and it gave results?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ankur Bawiskar
Tera Patron
Tera Patron

@Alon Grod 

it did work for me, do you have Work Order Tasks with that group which is being returned?

My Config

AnkurBawiskar_1-1765974015141.png

I am member of only 1 group

AnkurBawiskar_2-1765974047977.png

Output: it showed me INCs with that 1 group

AnkurBawiskar_0-1765973997886.png

 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar i belongs to 4 groups and i dont get any result and i do have wm_tasks with assignemnt groups as the groups that i belongs to

@Alon Grod 

check by running this script in background and see how many groups you get

var cr = [];
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', gs.getUserID());
gr.addQuery('group.active', true);
gr.query();
while (gr.next()) {
    var groupId = gr.getValue('group');
    if (!gs.nil((groupId))) {
        cr.push(groupId);
    }
}

gs.info(cr);

I got 1, you should get 4 in your case

AnkurBawiskar_0-1765974907201.png

 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader