What is the best way to send a notification using Business Rule, Script Action, or Email Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
"What is the best way to send a notification — including the Problem number and short description — when a Problem is created from an Incident, and should we use a Business Rule, Script Action, or Email Script for this, and in what order should each be executed?"
1. Business Rule (After Insert on Problem table)
(function executeRule(current, previous /*null when async*/) {
if (current.parent_incident) {
gs.eventQueue('custom.problem.created.from.incident', current, current.sys_id, current.parent_incident.sys_id);
}
})(current, previous);
2. Script Action (Triggered by Event)
var problem = current;
var incident = new GlideRecord('incident');
if (incident.get(event.parm2)) {
var email = new GlideEmailOutbound();
email.setSubject("New Problem Created from Incident: " + problem.number);
email.setBody("A Problem has been created.\n\nProblem: " + problem.number +
"\nShort Description: " + problem.short_description +
"\nRelated Incident: " + incident.number);
email.setRecipient(incident.caller_id.email);
email.send();
}
3. Email Notification
(function runMailScript( current, template,
email, email_action, event) {
var gr = new GlideRecord("problem");
gr.short_description = current.short_description;
var pid = gr.insert();
current.setValue('problem_id', pid);
current.problem_id = gr.sys_id;
current.setWorkflow(false);
current.update();
template.print("Problem Number: " + gr.number);
template.print("Problem Short Desc" + gr.short_description);
})(current, template, email, email_action, event);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Friday - last edited Friday
- A business rule is used when you want something to happen right after or before a record is created, updated, or deleted in this case after a problem is created it checks if it is linked to an incident and triggers an event
- Script action runs when that event is triggered here it sends an email with the problem number, short description, and related incident
- Email script is used when you want to format the email or generate complex content it is optional in this case because the email can be sent directly from the script action
The best way here is business rule to trigger the event and script action to send the email email script is only needed if you want special formatting.
Hope this helps!
If my response helped, please mark it as the accepted solution so others can benefit as well.
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution so others can benefit as well.