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

yup just figured that out.


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


gives me just the fields on the incident which are in the user/groups fields.



One more question I have is I have to get users, users/groups and all others under the whom to receive. And there may be sometimes param fields as well.Is there any way I get all the recipients dynamically?



find_real_file.png


There are


                                recipients_users


                                recipients_groups


                                recipient_fields


                                event_parm_1


                                event_param_2



Some are users, some fields on the incident. Each email notification can have one/many of these filled in. The email script I am trying to   build should take dynamically get which ever of the above is filled in. Can I do it using some command or do it individually ?


Try this in the email script


<mail_script>


var userArr=[];


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


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


userArr.push(current.fieldsArr[i].toString());


}


userArr.push(${event.parm1});


userArr.push(${event.parm2});


userArr.push(email_action.recipient_users.toString());


var gr= new GlideRecord("sys_user_has_role");


gr.addQuery('user','IN',userArr.toString());


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


gr.query();


if(gr.getRowCount()==userArr.length){


template.print(//here you will put in the link);


}


Unfortunately,


userArr.push(current.fieldsArr[i].toString()); or userArr.push(current getValue('fieldsArr[i])); is not returning null