How to Send a notification to created by using email script

PRAGHATIESH S
Tera Expert

How to send a notification to created by instead of assigned to not provided. Can anyone help me on the email script?

1 ACCEPTED SOLUTION

hello @PRAGHATIESH S ,

we cannot set TO address from email script there are no OOB methods i guess.

we can only set CC and BCC.

One work around is we can use event mechanism to set the TO address 

you can create a event in event registry table and write a script like below in a BR  on release table with your conditions and it can be an after insert BR

if(current.assigned_to=="")

{
var gr = new GlideRecord('sys_user');
gr.addQuery('user_name',current.sys_created_by);
gr.query();
if(gr.next())
{

gs.eventQueue('your_event_name',current,gr.sys_id,'');
}

}

else

{

gs.eventQueue('your_event_name',current,current.assigned_to,'');

}

And in your notification change the trigger condition to event and give your event name so that when this event fires it sends the notification.

Also you need to check Recipient contains parm1 check box  in the who will receive tab

hope this helps 

please mark my answer correct if this helps you

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

your email is on which table?

If it has opened_by field then use that.

If not then you will have to use event queue approach and trigger email via After insert BR on that table

Notification: Link with Event, Event parm1 contains Recipient - True

BR Script:

gs.eventQueue('event_name', current, gs.getUserID());

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi,

    Actually my table is Release[rm_release]. The notification send to assigned to , if assigned to not provided  then only send to created by. how to write the email script for that?

Hi @PRAGHATIESH S 

As I already said you cannot include created by in email directly.

You will have to use gs.eventQueue() approach which I already shared as 1st response to your question.

Did you mistakenly marked other response as correct?

You just had to enhance the script I shared

if(current.assigned_to)
	gs.eventQueue('event_name', current, current.assigned_to);
else
	gs.eventQueue('event_name', current, gs.getUserID());

Would you mind marking appropriate response as correct based on timely response?

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Upender Kumar
Mega Sage

In the email script below

var gr=new GlideRecord('sys_user');
gr.get('user_id',current.sys_created_by);
email.addAddress("to",gr.email,gr.name);

http://www.john-james-andersen.com/blog/service-now/send-new-servicenow-users-a-welcome-email-with-c...