Query Business rule based on assignment group

pooja53
Kilo Explorer

Hi Team,

I am writing the query Business rule. Where if Logged in user is member of that group, then only incidents belongs to that assignment group should be visible.

Before query business rule on Incident.

it works when I send Sys_id of that group example:

if(gs.getUser().isMemberOf('f795ab34db230010bdfd0181ca96196b'))
{
current.addQuery('assignment_group','f795ab34db230010bdfd0181ca96196b');
}

Its Not working below one.

if(gs.getUser().isMemberOf(current.assignment_group))
{
current.addQuery('assignment_group',current.assignment_group);
}

 

7 REPLIES 7

asifnoor
Kilo Patron

Hi Pooja,

Verify if current.assignment group is showing the right sys_id or not. I have added logs. below check once.

gs.log("Assignment group is "+current.assignment_group);
if(gs.getUser().isMemberOf(current.assignment_group))
{
gs.log("Entered into this");
current.addQuery('assignment_group',current.assignment_group);
}

Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.

Regards,
Asif
2020 ServiceNow Community MVP

Alok Das
Tera Guru

Hi Pooja,

Try using getUniqueValue() function, please find the updated script below:

if(gs.getUser().isMemberOf(current.assignment_group.getUniqueValue()))
	{
	current.addQuery('assignment_group',current.assignment_group.getUniqueValue());
	
}

Kindly mark my answer as Correct and helpful based on the Impact.

Regards,

Alok

Adrian Ubeda
Mega Sage
Mega Sage

Hi, 

If with current statement it's not working and you need to pass sys_id as value, create a property with the sys_id of the group and call it inside script as follows:

if(gs.getUser().isMemberOf(gs.getProperty('propertyName')){
    current.addQuery('assignment_group',propertyName);
}

//Also if you want to check over more than one group try this.
var groups = gs.getUser().getMyGroups().split(',');

if(groups.indexOf(gs.getProperty('propertyNanme').toString()) != -1)
{
current.addQuery('assignment_group', 'IN', groups.join());
}

Is it was helpful, please give positive feedback.

Thanks, 

If it was helpful, please give positive feedback! ✔
☆ Community Rising Star 22, 23 & 24 ☆