Email notification when new attachment is added or updated

tejumes
Kilo Guru

I'm trying to send an email notification to assignment group in incident task record when new/update attachment is added.

Any idea?

"Include Attachments" option sends only on the update in the incident record.

Any help on how to trigger an email notification when attachment alone added?

1 ACCEPTED SOLUTION

humblecommitted
Kilo Guru

Hello Teju,



I have used a similar method for onboarding new users.   Here is what I had to do.



I wanted new users on the project to upload required security documents.   Once they uploaded documents, based on the conditions that their attachments that were uploaded to their profile contained the key words "HIPAA" and "DHS" would trigger an event (notice the event name that is created is "onboard.attachment").



off the event, an email notification and template would be shot out.



BR - User Form Attach Notify


var userrec = new GlideRecord("sys_user");


userrec.get(current.table_sys_id);




var today = new GlideDate;


var pattern = "HIPAA";




var result = current.file_name.match(pattern);


if (JSUtil.has(result) ) {


  gs.log("filename " + current.file_name + " for user " + userrec.name + " contains " + pattern);


  gs.eventQueue('onboard.attachment', current, gs.getUserDisplayName(), userrec.name);


}


else {


  pattern = "DHS";


      result = current.file_name.match(pattern);


      if (JSUtil.has(result) ) {


      gs.log("filename " + current.file_name + " for user " + userrec.name + " contains " + pattern);


      gs.eventQueue('onboard.attachment', current, gs.getUserDisplayName(), userrec.name);


      }


  else gs.log("filename " + current.file_name + " for user " + userrec.name + " not matched to a pattern");


}


//gs.log("user " + userrec.name);


//if (userrec.sys_created_on > gs.daysAgo(30)) {


// gs.log(" new user " + userrec.name + ", created " + userrec.sys_created_on + " just attached file " + current.file_name   );




//Queue the email send event    


//Pass in event name, record(not applicable here), custom parm1, and custom parm2    


//Custom parm1 is the count of incidents queried and can be referenced from the email notification that responds to the queued event by using '${event.parm1}' in the email notification record.    


//gs.eventQueue('onboard.attachment', current, gs.getUserDisplayName(), userrec.name);


//gs.getUserName()


//}


//else gs.log(" old user attachment, created   " + userrec.sys_created_on + " just attached file " + current.file_name   );



1.1.jpg


1.2.jpg



The Email Notification that fires off the event named "onboard.attachment" and the email template associated with the email notification.


1.3.jpg


1.4.jpg



Now based on your request you were wanting to apply a similar situation to an incident.   simply change the code that references the "sys_user" table in the GlideRecord to the incident table and the file names that are being searched for.   You could also look at this old code we have when we were not searching attachments based on file names.



var userrec = new GlideRecord("sys_user");


  1. userrec.get(current.table_sys_id);


var today = new GlideDate;



  1. gs.log("user " + userrec.name);

if (userrec.sys_created_on > gs.daysAgo(14)) {


                              gs.log(" new user " + userrec.name + ", created " + userrec.sys_created_on + " just attached file " + current.file_name   );



//Queue the email send event    


//Pass in event name, record(not applicable here), custom parm1, and custom parm2    


//Custom parm1 is the count of incidents queried and can be referenced from the email notification that responds to the queued event by using '${event.parm1}' in the email notification record.    


  1. gs.eventQueue('onboard.attachment', current, gs.getUserDisplayName(), userrec.name);

//gs.getUserName()


}


else gs.log(" old user attachment, created   " + userrec.sys_created_on + " just attached file " + current.file_name );





I hope this helps.   Please let me know should you have any questions.



Sincerely,



Orlando Galindo


View solution in original post

25 REPLIES 25

Ravi Prasad1
Tera Guru

Trigger email notification on sys_attachment table whenever record got inserted into it.



Please add proper conditions.


williamsun
Mega Guru

I believe you are looking for the new attachment.uploaded event:


Administering Attachments - ServiceNow Wiki



(I say new, but it has been there since a few updates ago.)


From here you need to create a notification that triggers on the attachment.uploaded event when the table is incident and the assignment_group is not empty.


Thanks Sun , so you mean to create gs.eventqueue(attachment.uploaded....? If so can you help me with that


My table is u_incident_task


and i want to send it to assignment group when new or update (includes multiple attachments) added.


Not really, you don't have to do that even.


Just create a new Email Notification and click on the "Advanced view" link.


Then set the "Send when" to "Event is fired" and choose the "attachment.uploaded" event.


Then just fill out the who will receive and what it will contain tabs with the information you want.


Like this:


mailnotification.PNG