Business Rule against sys_email never fires off.

bigbacon
Giga Guru

I am trying to create a business rule to do something with an email after it is created (inserted) and I do not know what I am doing wrong but the BR never seems to fire off. It is like it is just ignored completely like it doesn't exist.

 

I created a very simple BR that on insert into sys_email set the body of the email to 'This is a test' and that never happens. 

 

Table: Email [sys_email]

Application: Global
Active: Checked
Insert is checked
Actions: Set field values [Body] to 'this is a test....'

that is it, very simple test and it just never does it. What am I missing?

 

11 REPLIES 11

SK Chand Basha
Giga Sage

Hi @bigbacon 

 

Before insert into the sys_email table you wants to be set it body? 

 

If yes, use before BR on Insert. 

 

Mark it helpful and Accept Solution!! If this helps you to understand. 

Ankur Bawiskar
Tera Patron
Tera Patron

@bigbacon 

what's your business requirement here?

If you are planning to set the body then please use Before Insert

Actions: Set field values [Body] to 'this is a test....' -> This will work only for Before Insert and Not After Insert

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

the goal was to attach a file to the email but the BR never kicked off. The example given on how to do this was an AFTER insert but again, it wouldn't fire off. this very basic BR was a test to figure out why and obviously we needed to use before insert to do anything.

 

Before was the key....

 

Now to figure out why i cant get the underlying case while the BR runs. Its like I can't query the case that caused the email to generate even though I can see the sys_id from current.instance and the current.target_table is correct as well. 


This is where we are stuck now. Just trying to get the case data. the query never finds anything.

 

(function executeRule(current, previous /*null when async*/) {

	var caseID = current.instance;

	if(caseID) {
		var caseRecord = new GlideRecord('sn_hr_core_case_benefits');

		if(caseRecord.get(caseID)) {
			var serviceid = c.getValue('sys_created_by');		
			current.setValue('body','test...' + current.target_table + '-' + current.instance + '-'  + caseRecord.getValue('sys_id'));
		}
		else {
			current.setValue('body','nothing found...' + current.target_table + '-' + current.caseID);
		}
	}
	else {
		current.setValue('body','nothing 1 found...' + current.target_table + '-' + current.caseID);
	}
}