Update record every time an email is sent from the Email Client

Patrick Fedigan
Giga Guru

Hello,

How would I update a record every time an email is generated and sent, say, from a incident?

I've looked into Email Client templates and doing a mail_script to update the record but that only runs when the email is composed.

Here is an image for how to generate an email from a record:

Screen Shot 2017-04-12 at 9.30.58 AM.png

Thanks

1 ACCEPTED SOLUTION

pareshwagh
Kilo Expert

Hi Patrick:



You can define a "after update" Business Rule on the sys_email table with the conditions State is Processed AND Type is sent and put the code for updating the Incident table in the Advanced section.



However, you will also need to define a way to figure out if this email was sent from the Incident form so that the logic is not triggered for every email that is sent out.


find_real_file.png


Hope that helps.


PS: Please hit "Correct", "Helpful" or "Like" depending on the impact of the response.


View solution in original post

5 REPLIES 5

kristenankeny
Tera Guru

It looks like you could potentially add a business rule to the sys_email table. Check if there is an entry for the email in sys_email_log. If not, then run the code you want to run on the incident.


pareshwagh
Kilo Expert

Hi Patrick:



You can define a "after update" Business Rule on the sys_email table with the conditions State is Processed AND Type is sent and put the code for updating the Incident table in the Advanced section.



However, you will also need to define a way to figure out if this email was sent from the Incident form so that the logic is not triggered for every email that is sent out.


find_real_file.png


Hope that helps.


PS: Please hit "Correct", "Helpful" or "Like" depending on the impact of the response.


Hi Pareshwagh,

Where is code please send the code.

restevao
Giga Expert

Additionally you can enhance the filter to only work on email client tickets by adding the condition.


- Error String > Changes from > User did not press the Send button in Email Client

- Type > is > send-ready

find_real_file.png

 

i have also used the following script so that in only updates the timestamps of the record.

 

(function executeRule(current, previous /*null when async*/) {
	var email_q = new GlideRecord(current.target_table);
	email_q.addQuery('sys_id',current.instance.toString());
	email_q.query();

	if (email_q.next())
	{
		//just updates the time stamp of the record.
		email_q.setWorkflow(false); 
		email_q.update();
	}
})(current, previous);