Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Hi @Anurag Tripathi , 

You mean array of emails would work? 

Because its an array it already separated by comma? 

Am I correct? 

I cant remember if you pass the array in the parameter it would work or not, but you can try that.

If it doesnt then add a .toString() when you pas it in eventQueue

-Anurag

Community Alums
Not applicable

Hi @Prathamesh Cha1 ,

Sorry my bad please check updated script below 

(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, userOfGroup1);
	}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);

 

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

Thanks and Regards 

Sarthak