P1 incidents should be created by only particular groups

Teja45
Tera Contributor

Hi All,

 

I have a requirement as below.

Priority 1 incident should be created/updated by the current logged-in user belonging to A,B, C groups or user having Admin role.

I have created a business rule as follows.

When to run : Before --> Insert/Update and priority is 1

Advanced :

 

(function executeRule(current, previous /*null when async*/) {


if ((!gs.getUser().isMemberOf("A") || !gs.getUser().isMemberOf("B") || !gs.getUser().isMemberOf("c") || !gs.getUser().hasRole('admin))
{
gs.addErrorMessage('you dont have the right to create/update P1 tickets');
current.setAbortAction(true);
}

})(current, previous);

 

But it is checking the only first condition and not working for all the three groups.

Can someone help me with this please?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

try this

(function executeRule(current, previous /*null when async*/) {

	if (gs.getUser().isMemberOf("A") || gs.getUser().isMemberOf("B") || gs.getUser().isMemberOf("c") || gs.hasRole('admin')){

	}
	else{	 
		gs.addErrorMessage('you dont have the right to create/update P1 tickets');
		current.setAbortAction(true);
	}

})(current, previous);

Regards
Ankur

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

View solution in original post

6 REPLIES 6

I have an requirement that only specific group (P1 group) should create  P1 ticket and Updation should be allowed by any one except urgency and priority fields. I had created 3 client scripts and it worked fine as now only P1 group members only able to create the P1 ticket and updation is allowed by any one. But now the requirement is updation of  P4 or P3 or P2 should be changed to P1 by only P1 group members.But now any body are able to change to P1. Can you please help on this

I had attached screen shots of 3 client scripts

Anil Lande
Kilo Patron

Hi,

Update it like below:

(function executeRule(current, previous /*null when async*/) {


if (!(gs.getUser().isMemberOf("A") || gs.getUser().isMemberOf("B") || gs.getUser().isMemberOf("c") || gs.getUser().hasRole('admin)))
{
gs.addErrorMessage('you dont have the right to create/update P1 tickets');
current.setAbortAction(true);
}

})(current, previous);

 

Thanks,
Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande