Help me to trigger email from business rule.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2024 07:36 AM
Hi All,
I want to add a watchlist when a particular type of request"New user" of one specific service catalog. I have created a business rule, event, and notification. However, the email notification trigger is not working. Can anyone help me with the code, please?
Please find the screenshot for reference.
Business rule code below
Regards,
Naganandini N
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2024 07:41 AM
Hi @NaganandiniN,
please check below script:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var request = current.variables.type_of_request;
gs.debug('Type of request: ' + request);
if (request == 'New User') {
// Log the action of setting the watch list
gs.debug('Setting watch list for New User request');
// Set the watch list
current.watch_list = '4764436f1bde4090c069fd15cc4bcbb5';
// Update the current record
current.update();
// Log the event queue action
gs.debug('Queuing event ijm.facilities.new.user.creation');
// Queue the event
gs.eventQueue('ijm.facilities.new.user.creation', current, gs.getUserID(), gs.getUserName());
}
})(current, previous);
Thank you, please make helpful if you accept the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2024 07:50 AM
Hi @NaganandiniN
Check that an event is getting triggered in event logs[sysevent].Make sure the event name defined in event registry is same as that in the event generation(Name that comes up in the event logs).
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful."
Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2024 08:31 AM
@NaganandiniN First thing first, never ever use current.update(); in a before business rule. Simply comment current.update in the script as this is before business rule, the changes on the current record are anyways going to be stored in database. current.update() is only going to cause recursive calling of the business rule.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var request=current.variables.type_of_request;
if(request=='New User')
{
//current.watch_list='facilities@ijm.org';
current.watch_list='4764436f1bde4090c069fd15cc4bcbb5';
gs.eventQueue('ijm.facilities.new.user.creation', current, gs.getUserID(), gs.getUserName());
}
})(current, previous);
Also, add a gs.addInfoMessage() inside your business rule to verify if your business rule is actually being called or not. It appears to me that the conditions defined on the BR are not meeting and hence the business rule is not getting called.
Please verify.