Hide Assignment group based on current user's assignment group.

Maxwell3
Kilo Guru

Hello Community,

I would like users who are members of 'Generic Group' and are currently logged in to have access and to be able to see all the Assignment groups available on the Incident form. On the other hand, if a user who is currently logged in, is not a member of the 'Generic group', the group name 'Hidden Group' shall be hidden from that user.

My organization already has a script include in the assignment group field reference qualifier. I created a script include and tried to use it in addition to the my organization's script include and I also tried to use mine by itself but it still did not work.

Reference Qualifier:

javascript: myGroupFilter();

Script Include:

var myGroupFilter = Class.create();
myGroupFilter.prototype = {
initialize: function() {

if (gs.getUserID().isMemberOf('Generic Group'))
{ // User Can see all records
return;
}

else
{
return 'name!=Hidden Group'; // If user is not a member of the Generic Group Name then HIDE this Assignment group field.
}

},

type: 'myGroupFilter'
};

 

Below is what I had, I removed my organization's script include but it still did not work?

javascript: myOrganizationScriptInclude()+myGroupFilter();

1 ACCEPTED SOLUTION

@Maxwell 

try

javascript: new MyOrgScriptInclude().getOrgQuery(current.u_org_field) + '^'+ new MyOrgScriptInclude().filter();

also change

var myGroupQuery = Class.create();
myGroupQuery.prototype = {
	
	filter: function(){
		if (!gs.getUser().isMemberOf('Generic Group Name')){
			return 'name!=Hidden Group';
		}else{
			return '';
		}
	},
	
	type: 'myGroupQuery'
};

View solution in original post

8 REPLIES 8

Thank you, that helped.

Thanks, Looks like you marked your response as correct. Please make necessary update.

The SN Nerd
Giga Sage
Giga Sage

I'd advise doing this by role, not by group.

Give the group a role - something like 'assign_all_groups' and do your check based on role.

gs.hasRole('assign_all_groups');

Second, to that, I would give your hidden groups a type of 'hidden' and do your reference qualifier that way.

Why?

Because it is much more scalable.

You can assign the privileges out to other groups, change group names, or even assign to individuals (although not advised).

It is also easier to implement client-side controls with roles. 

Think of a role as something that grants a capability, and Group membership grants capabilities to people.


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

please try this simpler approach; no need to have script include

javascript: var query=''; if(!gs.getUser().isMemberOf('Generic Group')) query = 'name!=Hidden Group'; else query;

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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