sending an email from within a script

drslry2
Tera Contributor

Hi Gurus,

I'm attempting to run a script that updates a table then sends an email after the update.

The update of the table works fine, however the sending of the email does not.

The lines in bold below do not appear to be working properly.  

Can anyone tell me how to send an outbound email directly from a script?

Any info will be appreciated.

Thanks in advance!

var user = email.body.employee.toString();

var gr = new GlideRecord('sys_user');

gr.addQuery('email',user);  

gr.query();

gs.log(gr.getRowCount());

if (gr.next())

{

        gr.active = false;

        gr.update();

email.setFrom("umassmeddev@service-now.com");

email.setReplyTo("robert.poschmann@umassmed.edu");

email.setSubject("This is the new subject line");

email.setBody("This is the new body");

}

19 REPLIES 19

This is not the event . The event name you opened from the log is not - Update User Test . In event log you should search for the event that you expect to fire. which is "Update User Test"


drslry2
Tera Contributor

sorry about that, here it is....


find_real_file.png


find_real_file.png


The event state is error , so the event is not processed . can you try with gs.eventQueue('Update User Test', current, '3a5754b64f0ade00cdf248f18110c7b7',null);   ?


rjp
Tera Expert

Unfortunately this statement is not working...gs.eventQueue('Update User Test', current, '3a5754b64f0ade00cdf248f18110c7b7',null);


and neither is this one...gs.eventQueue('Update User Test', current, gs.getUserID() , gs.getUserName() );



and the state says 'error' , very vague, is there anyway to get more information about what is causing the error?



and do i need an event to trigger a notification, can i call the notification straight from the code?



find_real_file.png


rjp
Tera Expert

Ok, I believe the problem was the following checkboxes in the notification were not set.


After checking them, it worked.



Now i have to find out how to send parameters to the notification.



Thanks for all your help and patience.



find_real_file.png