Trigger email notification based on Event

susunow
Tera Contributor

Hi,

 

I would like create a schedule script that runs an event every 6th of the month. 

This event consists of triggering an email notification for Change Request ticket that has different email recipients (email to, not bcc or cc) for different locations according to the variables on the ticket.

Is it possible and how to add these list of email recipients in the schedule script execution. How do i start?

 

Thank you!

2 REPLIES 2

Barath P
Tera Guru

Hi @susunow ,

Yes, it's possible to create a scheduled script and that triggers an email notification based on location variables from Change Request tickets. create a new scheduled script execution. Set the Run field to Monthly and select the Day as 6 to run the script on the 6th of every month. 

Here’s a script example:

 

var changeRequestGR = new GlideRecord('change_request');
changeRequestGR.addQuery('state', 'Open');  
changeRequestGR.query();

while (changeRequestGR.next()) {
    var location = changeRequestGR.variables.location; 
    
    var emailRecipients = '';
    
    if (location == 'Location1') {
        emailRecipients = 'email1@example.com';
    } else if (location == 'Location2') {
        emailRecipients = 'email2@example.com';
    }
    // Add more location-based conditions here
    
    // Trigger the email notification
    gs.eventQueue('change.notification.event', changeRequestGR, emailRecipients, null);
}

 


Create a new notification for the event (change.notification.event). Add conditions that determine when the notification should be triggered. example when the location field changes.

"If you found my answer helpful, please give it a like and mark it as the accepted solution. It helps others find the solution more easily and supports the community!"

 

Thanks & Regards,

Barath.P



susunow
Tera Contributor

How about if i wanted to add more than one email address per location?