How to trigger mail whenever attachment is added for incident

ankurpd001
Tera Contributor

I want to know how to trigger email whenever i add attachment to incident ticket.
Mail should be trigger to "Caller"

1 ACCEPTED SOLUTION

ccajohnson
Kilo Sage

Attachments are stored on a separate table called Attachment. There are details on this Attachment record that point to the table that this attachment is related to. Since you want to send an email, here is what you need to do:


1.   Create an Event to use with your notification:


      A.   Navigate to System Policy > Registry.


      B.   Click New to create a new Registry. Here are the details for the Event Registry record:


      Event name: incident.attachment.add


      Table: Incident [incident]


      Description: Used to send a notification when an attachment is added.


      Fired by: Business Rule



2.   Create a Business rule to trigger the event:


      Name: Send Event for Incident Attachment add


      Table: Attachment [sys_attachment]


      Advanced: true


      Description: Sends an event when an attachment is added to the Incident table


      When: after


      Order: 100


      Insert: true


      Update: false


      Delete: false


      Query: false


      Condition: current.table_name == 'incident'


      Script:


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


      var incObj = new GlideRecord('incident');


      if (incObj.get(current.table_sys_id)) {


              gs.eventQueue('incident.attachment.add', incObj, current.file_name);


      }


})(current, previous);



3.   Create your notification:


      Name: INC-Attachment Added


      Table: Incident [incident]


      Send when: Event is fired


      Event name: incident.attachment.add


      Users/groups in fields: Caller


      Subject: Attachment ${event.parm1} has been added to Incident ${number}




Let me know if you have any questions,


View solution in original post

14 REPLIES 14

ankurpd001
Tera Contributor

Thanks Christopher it's working.


Be sure to mark the answer as correct so that others with a similar need can refer to this post.


bostonsnow
Kilo Guru

Had the same request and this is also working for me. Thanks ccajohnson!

bostonsnow
Kilo Guru

@ccajohnson I'd like to add this for my RITM's as well. I followed the steps above changing the table to sc_req_item and then changed the script to the following (which I'm almost positive is not right). 

 

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


var itemObj = new GlideRecord('sc_req_item');


if (itemObj.get(current.table_sys_id)) {


gs.eventQueue('sc_req_item.attachment.add', itemObj, current.file_name);


}


})(current, previous);

 

What did I miss?

 

Thanks,

 

Mike

Did you create the event registry? Follow the same steps as for Incident, but be sure to have the table be the table you changed in your script. You also need to make sure the notification resides on the same table as the event you created. Finally make sure the Business Rule is on the new table as well.