how can i trigger email notification from business rule script

amitkishore
Giga Contributor

Hi There,

I have written a business rule and have script (By clicking an Advance checkbox) in it.

I have to send a notification based on some condition in script. hence I have written email notification separately but don't wanna trigger based on "table or condition" present on the email notification form, though I want to get this email notification send bested on condition written in business rule script.

can some one please help me know can I configure the same.

Regards,

Amit

 

 

 

1 ACCEPTED SOLUTION

asifnoor
Kilo Patron

Hello Amit,

I have written a article explaining how you can trigger a notification from Business Rule. Kindly go through and this shall help you.

Setup email notification using Business rule.

Mark the comment as a correct answer and also helpful if it helps.

View solution in original post

8 REPLIES 8

Narendra Kota
Mega Sage

You can write an event in Event Registry (sysevent_register) table and call that event in business rule which in turn, event triggers the notification.

Example script (business rule) to call the event:

FYI : Non-FTE_updates is the name of Event

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

	// Add your code here
	//gs.log('The Event should fire', 'Narendra');
	var manager = current.u_user_name.manager.toString();
	gs.eventQueue("Non-FTE_updates", current, manager, gs.getUserName());
	
})(current, previous);

 

Hope this helps.
Mark helpful or correct based on impact.

Thanks.

Jeff Currier
ServiceNow Employee
ServiceNow Employee

Or you could go with a more modern approach and skip the business rule and use Flow Designer for your notification.  You can still put your condition in a script if necessary.

I tried to use the modern approach but the notification will only execute when I'm testing it. It will not work when I place the notification action in the Flow Designer as an action and drag and drop the associated "record" from the trigger. I tried dragging the "Sys ID" from the data pill or the "Record" itself from the trigger. The trigger is based on "Created" records, and then I want the notification action to execute. It does not work this way. If I select a record for testing. The notification executes.

Jeff Currier
ServiceNow Employee
ServiceNow Employee

Not clear on what doesn't work when you do it for real, not testing.  Does the trigger not fire or does the notification not send?  You should be able to look at executions to see if it is triggering.  If not triggering, then you know where to focus.  If triggering but not send or sending the wrong info, the executions detail should tell you why.  This should work for you.