Add a variable value as to field in notification

Bidduam
Tera Guru

I need to workout how to get the value of a variable into the to field of a notification.

 

Eg: I have a text field called "u_email_address" and I need to make whatever is typed in there to be added to the "Who will receive" section of the notification (figuratively speaking at least).

Bidduam_0-1677551986248.png

 

I would also like to know how I can add an attachment to the notification email that is sent as well. As in we have a particular file that needs to be sent with the email that is sent for a particular type of request.

 

 

1 ACCEPTED SOLUTION

Hi,

Unfortunately, you can't set the "To" in mail script, which is why I had mentioned CC. You can also set BCC, but I'm sure that's even further away from what you're trying to do. So...for the "To", that is where the creation of an event, triggering that, to fire a notification would be helpful because when firing the event you can specify parm1 or parm2 in that. Then, in the notification, in the "who to send to" tab, you can check the box (either parm1 or parm2) that contains recipients, thus setting the "To".

 

In any case, the mail script for setting "CC" would be like so, this has other examples as well to help you along: https://docs.servicenow.com/en-US/bundle/tokyo-servicenow-platform/page/script/server-scripting/refe... 


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

View solution in original post

3 REPLIES 3

Allen Andreas
Administrator
Administrator

Hi,

If the field is not present in the "Users/Groups in fields", then you'd have to use a mail script to add the recipient to the email (as a CC). If you're needing the sole recipient to be the email address typed into that field, then you may want to create an event, and then in a business rule or some other process...trigger that event (and then pass the field value for that field as a parm1). Then, within a notification, set it to fire when the event you created is triggered and then in the "who to send to" tab, check the box for parm1 contains recipients.

 

As far as the attachment goes, you can review my article here that talks about an image attachment, though you should be able to use any type, the principal is the same: https://www.servicenow.com/community/developer-articles/embedding-image-attachments-in-the-body-of-n... 


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

Thank you @Allen Andreas especially for the attachment link - that looks like it will do exactly what I'm wanting to do.

 

As for the mail script and the cc, firstly is there a reason it has to be the CC? and do you have an example of how the mail script would look? 

Hi,

Unfortunately, you can't set the "To" in mail script, which is why I had mentioned CC. You can also set BCC, but I'm sure that's even further away from what you're trying to do. So...for the "To", that is where the creation of an event, triggering that, to fire a notification would be helpful because when firing the event you can specify parm1 or parm2 in that. Then, in the notification, in the "who to send to" tab, you can check the box (either parm1 or parm2) that contains recipients, thus setting the "To".

 

In any case, the mail script for setting "CC" would be like so, this has other examples as well to help you along: https://docs.servicenow.com/en-US/bundle/tokyo-servicenow-platform/page/script/server-scripting/refe... 


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