Scripting To field in Email Client Template

milosnew
Tera Contributor

Is possible to set custom values in Email Client Template in To field using script includes?

I already tried, and getting like current is undefined?

1 ACCEPTED SOLUTION

Andrew Barnes -
ServiceNow Employee
ServiceNow Employee

Greetings Milo,

 The email client template system doesn't use the current.fieldname - instead it references the fields without current. This would seem to preclude the use of script includes that rely on using current object. Docs

-Andrew Barnes
Join me at Developer Blog

View solution in original post

7 REPLIES 7

Hello,

That field will not trigger a javascript as far as I know.
What you do is:

  • Create a Notification Email Script that first calls the Script Include
  • Take the data received from the Script Include and in your email script and add it to CC (to add to "To:" field you need to have the address in the form, such as ${caller_id.email} for incident)
    • In the script: email.addAddress('cc', addresses ) will add addresses to CC field
  • In your Email Client Template, somewhere in the body (as it does not add any text to the email, it will not be visible in the finished, sent, email) add your email script using:
    • ${mail_script:name_of_script}

You can try add your mail script in the To -field (as it does take ${caller_id} ), but I have not tried that myself.
I usually add addresses to BCC, as there is no real reason for everyone to know everyone else.

Read more here: https://docs.servicenow.com/bundle/london-servicenow-platform/page/script/server-scripting/reference/r_ExScptEmlNtfn.html

I hope this helps, and if so, please this as resolution to your ticket.

With regards
Anton

Will it be processed on opening email client?

It should trigger on opening, but I can't remember at the moment if it does.