Send Email In UI Action

stevejarman
Giga Guru

Can someone point me in the direction of how to send an email directly from a UI Action script? Sorry if I'm missing something obvious, but I haven't found this documented as yet.

As an example, on a Change Request, I want to add a UI Action that gives me a "Start Work" button. When the owner of the CR hits that button, I'll (amongst other things) have the UI Action script send an email to the change advisory board to let them know the CR is starting. I essentially want the equivalent of Javascript:

SendEmail("changeboard@somewhere.com", "This is the subject", "This is the HTML body");

Or

SendEmail("changeboard@somewhere.com", UsingThisTemplate);

Is there such a thing, or something along those lines?

1 ACCEPTED SOLUTION

While not as flexible as a notification, you can hard code an email via script that can be called by a UI action. Below is an example:



var emailNotification = new GlideRecord('sys_email');


emailNotification.type = 'send-ready';


emailNotification.subject = 'Email subject';


emailNotification.body = 'Email body';


emailNotification.recipients = email-adress1 + ',' + email-address2;


emailNotification.insert();


View solution in original post

9 REPLIES 9

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

HI Steve,



It could be achieved by creating a email notification and then trigger the notification from UI Action by triggering the event.


http://wiki.servicenow.com/index.php?title=Events_and_Email_Notification



The other option is, OOTB we do have email client functionality. Is that something you are looking for.


Enabling the Email Client - ServiceNow Wiki


Okay - so I can't do it directly, but maybe I can create a new field "InProgress", have the "Start Work" UI Action set InProgress to true, and then a new event that fires a notification whenever InProgress is set to true. I'll have to experiment.


While not as flexible as a notification, you can hard code an email via script that can be called by a UI action. Below is an example:



var emailNotification = new GlideRecord('sys_email');


emailNotification.type = 'send-ready';


emailNotification.subject = 'Email subject';


emailNotification.body = 'Email body';


emailNotification.recipients = email-adress1 + ',' + email-address2;


emailNotification.insert();


Lovely! Exactly what I needed