How to set send to in notification based on Integer Field?

Prathamesh Cha1
Tera Contributor

Hi Team

 

I am having Integer field 

If that field value is 0 then notification should send to assigned to's manager and if

If that field value is 1/2 then notification should send to assigned to's manager  and group 1 and if

If that field value is 3+ then notification should send to assigned to's manager and group 2

 

notification is same, body and other thing are same just I want to change "send to" based on Integer Field.

How to achieve this?

7 REPLIES 7

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

You can trigger the notification in a br using gs.eventQueue and pass the recipient as a parameter.

 

gs.eventQueue('<event>',current,<user record>);

Email Body

AnuragTripathi_0-1725612713323.png

 

PS, this option shows up when email is triggered by event

 

-Anurag

Community Alums
Not applicable

Hi @Prathamesh Cha1 ,

Please create a before business rule and add specific table, click on advance check box and than select before and check insert or update checkbox and add below script 

SarthakKashyap_0-1725613040941.png

 

 

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

	// Add your code here
	var num = current.getValue("u_enter_number");
	if(num == 0){
		gs.eventQueue('assignedTo.manager', current, current.assigned_to.manager, current.assigned_to);
	}else if(num ==1 || num == 2){
		var userOfGroup1 = [];
		var gr = new GlideRecord("sys_user_grmember");
		gr.addQuery('group', '8a4dde73c6112278017a6a4baf547aa7');//sys_id of group1
		gr.query();
		while(gr.next()){
			userOfGroup1.push(gr.user.email);
		}
		gs.eventQueue('assignedTo.manager.group1', current, current.assigned_to.manager, gr.user.email);
	}else if(num == 3){
		var userOfGroup2 = [];
		var gr1 = new GlideRecord("sys_user_grmember");
		gr1.addQuery('group', '8a4dde73c6112278017a6a4baf547aa7');//sys_id of group2
		gr1.query();
		while(gr1.next()){
			userOfGroup2.push(gr1.user.email);
		}
		gs.eventQueue('assignedTo.manager.group2', current, current.assigned_to.manager, userOfGroup2);
	}

})(current, previous);

 

Create 3 event as I mentioned in script and select specific table in my case incident is the table 

 

Create 3 notification and select event in particular notification, in who will receive tab please check the checkbox of 

Event parm 1 contains replicants and Event parm 2 contains replicants

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak

Hi @Community Alums , 

One doubt why for num = 1/2, you have used email of user and for num = 3 you have used array of emails

Which one should I consider because in both cases I am sending notifications to group members. 

Comma separated emails would work. 

-Anurag