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.

Recipient list in notification script in email

ryadavalli
Tera Expert

Can I get the list of recipients in a email notification script which I am using the email, before it is sent out. I know we can get if it is a field in the form, but from the

whom to fields?

1 ACCEPTED SOLUTION

Ravali,



  Here is your complete email script. I have tested this and it should work for you as well.


var userArr=[];


var count=0;


var fieldsArr1=email_action.recipient_users.toString().split(',');


var fieldsArr2=email_action.recipient_groups.toString().split(',');


var fieldsArr3 = email_action.recipient_fields.toString().split(',');


if(fieldsArr1)


  {


  for(var i=0; i<fieldsArr1.length; i++){


  userArr.push(fieldsArr1[i]);


  }


}


if(fieldsArr2)


  {


  for(var i=0; i<fieldsArr2.length; i++){


  var gr= new GlideRecord('sys_user_grmember');


  gr.addQuery('group',fieldsArr2[i]);


  gr.query();


  while(gr.next()){


  userArr.push(gr.getValue('user'));


  }


  }


}


if(fieldsArr3)


  {


  for(var i=0; i<fieldsArr3.length; i++){


  var inc_field = fieldsArr3[i].toString();


  userArr.push(current.getValue(inc_field));


  }


}


if(email_action.event_parm_1!='')


  {


  userArr.push(event.parm1);


}


if(email_action.event_parm_2!='')


  {


  userArr.push(event.parm2);


}


var arrayUtil = new ArrayUtil();


var gr1= new GlideRecord("sys_user_has_role");


gr1.addQuery('user','IN',arrayUtil.unique(userArr).toString());


gr1.addQuery('role.name','itil');


gr1.query();


if(gr1.getRowCount()==arrayUtil.unique(userArr).length){


  template.print("Click here to View: "+'${URI_REF}');


}


View solution in original post

46 REPLIES 46

Any ideas?


You can write email script. Where are your recipients coming from? From a field or a n event parameter?


Hmm but the email has not been sent and all it has is whom to send = assigned to. In the email template of the same, can I check the recipient before email is sent out ! I tried it dodnot work


So, in the notification, who will receive section, you are selecting the field assigned_to as recipient right?


Yes the notification goes to assigned to and the watch list person. But I was show a link which is in a email notification only if the recipients (assigned to and watchlist) is all itil users. If even one is no itil, I want to hide the link.