Set dynamic email address in Notification

vw1
Giga Contributor

Hi all,

I have a custom field on [Walk-up Appointment] that holds an alternate email address.

I would like to see if we could input the field into a notification, so it sends directly to the email address field, either through the Notification object or by script. 

 

find_real_file.png

 

Thank you.

1 ACCEPTED SOLUTION

Allen Andreas
Administrator
Administrator

Hi,

You can use mail script to achieve this. Please refer to documentation such as: https://docs.servicenow.com/bundle/rome-servicenow-platform/page/script/server-scripting/reference/r...

So you'd create a mail script using, example:

email.addAddress("cc",current.email_field);
or
email.addAddress("bcc",current.email_field);

Then in the notification body you can use:

${mail_script:name_of_mail_script}

You're unable to use mail script for the "to" field, but you can use an event and pass the email address as parm1 or parm2 and then use that in your notification.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

4 REPLIES 4

Allen Andreas
Administrator
Administrator

Hi,

You can use mail script to achieve this. Please refer to documentation such as: https://docs.servicenow.com/bundle/rome-servicenow-platform/page/script/server-scripting/reference/r...

So you'd create a mail script using, example:

email.addAddress("cc",current.email_field);
or
email.addAddress("bcc",current.email_field);

Then in the notification body you can use:

${mail_script:name_of_mail_script}

You're unable to use mail script for the "to" field, but you can use an event and pass the email address as parm1 or parm2 and then use that in your notification.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi Allen, 

 

Thank you for the solution. As for the event solution, could you explain more how that could be put in place? Would it require Business Rules to trigger the event? 

 

Thank you.

Vikki

Hello,

Doesn't necessarily need a business rule for it to fire, but you could do that. I don't know the specifics on "when" you want the notification to send, but you would need to determine that on your end. You could then use an onAfter business rule that if the condition 'x' is met, you fire the event:

https://docs.servicenow.com/bundle/rome-platform-administration/page/administer/platform-events/task...

and then you'd pass that field's value as parm1 (refer to documentation above), for exmaple.

Then in the notification, you'd change it from firing how it is now and instead choose "when event triggered" and select your newly created event that you'll make for this process. Then in the "who to send to" tab, you'd select "parm1 contains recipients" because you've now set it up to include that email value in your parm1.

Please mark reply as Helpful, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

hi,

thanks a lot.

it works, but why 'to' does not work?

email.addAddress("to",current.email_field);