How to set "Who will receive" through mail script?

m_servicenow
Kilo Contributor

Hi Everyone,

I want to add "Who will receive' from <mail_script></mail_script>. is there any way by which we can set user/group filed in "Who will receive".

I m writing this code as below in <mail_script> in email template. But this is not working:

<mail_script>

var gr = new GlideRecord("change_request");

gr.addQuery("number", current.number);

gr.query();

if(gr.next())

{

  var emailto=gr.requested_by.user_name+"@example.com";

    email.setTo(emailto);

}

  </mail_script>

18 REPLIES 18

Yes in email notification body.



You can pass user sys_id as well if you dont have email ids.


YUp it worked, but one question is we cannot have bcc or cc without to right ?


Hi Ravali,



Could you please share a screenshot from the notification body where exactly you have written the mail script in Geneva. Also if you could provide script to cc users manager would be great.



Regards


Adarsh


Here is the email notification body:



Short description: ${short_description}


${mail_script: your mail script name}





In the email script, you can use:




(function runMailScript(current, template, email, email_action, event) {



if (!current.caller_id.nil()) {


 


  var id = current.caller_id;


  var user = new GlideRecord("sys_user");


  if(user.get(id))


    {


    if(user.manager != '')


      {


      email.addAddress("cc", user.manager.email, user.manager.getDisplayValue());


    }  


  }


}


})(current, template, email, email_action, event);



On Istanbul, the "Event parm 1 contains recipient" is missing. Is this still supported. My notification is fired on an event.


Am I missing something?



Thanks,


Jay