The CreatorCon Call for Content is officially open! Get started here.

how to trigger notification from Business rules?

instance
Tera Contributor

In the Additional Comments Field , whenever @User name is used Email is sent . and those details are stored in the live_notification Table .

 

so the Business rules should trigger when the live_notificaiton is created for that particular Incident record and the OOB notification should trigger for that particular Caller_id.

and the email sent should be displayed in the activity stream .

 

Businee rule 

table : Live_notification.

when to run after insert and update

 

(function executeRule(current, previous /*null when async*/) {
var user = new GlideRecord('live_notification');
user.addEncodedQuery('profile' + current.comments.getJournalEntry());
user.addEncodedQuery('document' + current.sys_id);
user.orderByDesc('sys_created_on');
//user.addEncodedQuery('field_name=comments' );
user.query();
gs.log('live= ' + current.comments.getJournalEntry(1));
if(user.next()) {


gs.eventQueue('Activity Stream @Mention Email',current,gs.getUserID(),gs.getUserName());


}
})(current, previous);

 

Notification is OOB : Activity Stream @Mention Email.

 

notification is not displaying in the Activity stream.

how tosolve this issue?

6 REPLIES 6

Uncle Rob
Kilo Patron

This is exactly what events are for.  You'll notice in your notifications one of the firing conditions is on event.

Here's a couple videos I did to show you how it works.

 

 

And if you need to schedule hte event into the future....

@Uncle Rob the script which i have created is not executing what is wrong in the script?

I'm not 100% sure but this looks suspect

RobertFedoruk_0-1677503302816.png

I think you meant to put an = in there?   'profile='

raphaelcrv
Kilo Guru

So follow the step by step how to trigger a notification from a business rule:

1. First Step, create a event registry.
On the filter navigator filter by "Events" and select Registry under System Policy > Events >

raphaelcrv_0-1677437091272.png

 

2. Create a business rule, on my example bellow we are going to trigger every time when category is software and send a e-mail to the current user who created the record or update.

raphaelcrv_1-1677437343355.png

Go to the advance table on the business rule created and add the following script:.

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

	// Add your code here
	//trigger the notification example

	gs.eventQueue("live.notify",current,current.user.email,"Category Is Software");
	//event name // glide record current // email // param3 could be anything

})(current, previous);

 

3. Create the notification, make sure to select the correct event name created on the previous step

raphaelcrv_2-1677437488724.png

 

 on who will receive:
flag theEvent parm1 contains recipient in order to set the recipient on the business rule

raphaelcrv_4-1677437662268.png

On what will contain select the content of notification, subject, body and etc.. .

on my example im using the param2 to set the data on the notification

raphaelcrv_5-1677437692406.png

 

Now lets create a incident record, the record was created and the business rule triggered following the conditions insert/update and category = software

raphaelcrv_6-1677438373349.png

 

And the business rule triggered the event we can see the log on sys_event

raphaelcrv_7-1677438445982.png

And also the outbox notification record was created 

raphaelcrv_8-1677438481555.png


Hope that helps, and please let me know if u have any question im glad to help you

 

 

 

 

 

 

 

If my response was helpful and/or provided a solution, please consider marking it as such. Thank you!