When a change request is completed, send an email to the assigned to person on all related problems

CHITTARANJAM
Tera Contributor
 
1 REPLY 1

Nilesh Pol
Tera Guru

Hi @CHITTARANJAM 

use below script in BR on change request table:

(function executeRule(current, previous /*null when async*/) {
// Ensure the state changed to "Completed"
if (current.state.changesTo("Closed") || current.state.changesTo("Completed")) {

// Query all related Problems
var problemGR = new GlideRecord('problem');
problemGR.addQuery('change_request', current.sys_id); // Find problems linked to this change
problemGR.query();

while (problemGR.next()) {
if (problemGR.assigned_to) {
var emailBody = "Dear " + problemGR.assigned_to.getDisplayValue() + ",\n\n";
emailBody += "The related Change Request (" + current.number + ") has been completed.\n";
emailBody += "Please review if any further actions are needed for your Problem record (" + problemGR.number + ").\n\n";
emailBody += "Best regards,\nChange Management Team";

// Trigger Email Event
gs.eventQueue('change.completed.problem.notify', problemGR, problemGR.assigned_to, emailBody);

gs.info("Notification sent to " + problemGR.assigned_to.getDisplayValue() + " for Problem: " + problemGR.number);
}
}
}
})(current, previous);

 

then

Step 2: Create Email Notification

  1. Navigate to: System Notification > Email > Notifications
  2. Click "New" and configure:
    • Name: Change Request Completed - Notify Problem Owner
    • Table: Problem
    • Event Name: change.completed.problem.notify
    • Who will receive: Assigned To
    • Message:

      Hello ${assigned_to},

      The Change Request (${change_request.number}) associated with your Problem (${number}) has been completed.

      Please take any necessary actions.

      Regards,
      Change Management Team