Group Only create when name start with Serv_Notif_ and type is customer notifications

Kunal33
Tera Expert

Hi Team,

 

We have a requirement where new group only created when group name start with Serv_Notif_ and type is customer notification by user.

I have created a business rule which restricted when name not start with Serv_Notif_ and type is customer notification but its not working .

 

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

var Name = current.name;
gs.addInfoMessage(Name);
var Type = current.type;
gs.addInfoMessage(Type);
if (Name.STARTSWITH('Serv_Notif_')^Type.LIKE('87a7c92a1b494150533699371d4bcbb5')){
gs.addInfoMessage("New Group Created");

} else {
gs.addErrorMessage("Please select Type as Customer notification and name start with Serv_Notif_");
current.setAbortAction(true);
}


// Add your code here

})(current, previous);

 

Can any one please help me here.

 

Thanks!

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Kunal33 

your BR should be before insert

Update with this script

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

	var Name = current.name;
	var Type = current.type;
	if (Name.toString().startsWith('Serv_Notif_') && Type.indexOf('87a7c92a1b494150533699371d4bcbb5') > -1){
		gs.addInfoMessage("New Group Created");
	} else {
		gs.addErrorMessage("Please select Type as Customer notification and name start with Serv_Notif_");
		current.setAbortAction(true);
	}
	// Add your code here

})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@Kunal33 

your BR should be before insert

Update with this script

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

	var Name = current.name;
	var Type = current.type;
	if (Name.toString().startsWith('Serv_Notif_') && Type.indexOf('87a7c92a1b494150533699371d4bcbb5') > -1){
		gs.addInfoMessage("New Group Created");
	} else {
		gs.addErrorMessage("Please select Type as Customer notification and name start with Serv_Notif_");
		current.setAbortAction(true);
	}
	// Add your code here

})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Hi @Ankur Bawiskar - Thanks for helping me out here. i need one more help.

 

I need to add user to the group if type is customer notifications. i create an ACL when i add the condition that group.type is cutomer notification then edit button is omit on group table

 

I have created a create ACL on Group membership table and added particular role . when i add the conditon group.type is cutomer notification, edit button omits from group table

@Kunal33 

you can restrict it via BR as well

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

Can you help me with the BR.?