We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

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

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  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

Gabor10
Mega Guru

|| should be && for your logic, shouldn't it?

Not applicable

Hi Teja,

 

Try below steps:

1) Have onSubmit client script

2) Get value of priority

3) Determine if logged in user is part of 'service Desk/your group name' group. this will be a flag either true/false

4) if (priority == 'high' && flag == true){

alert("you dont have access to create this ticket");

return false; // this will stop user from submitting the form

}

 

Mark my answer correct & Helpful, if Applicable.

Thanks,

Sandeep

Ankur Bawiskar
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  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

Thank you @Ankur Bawiskar it worked.