SysAttachment

KingSukh
Tera Expert

I am trying to generate an email when a user attaches a file to a form i.e finance form that is attached to a record producer and it triggers a workflow.


u_finance inherits from sc_req_item which inherits from task, how can i get the assigned_to list from the tasks table through dot walking back.

I need to generate an attachment notification with the word that something was attached so that it can be filtered, i already log it in the comments section however it sends a generic email out based on a template. Alternatively i can search through comments and associated dates and if any comment as of today has the word attachment put that in the body or subject of the email.

9 REPLIES 9

David OBrien
Kilo Guru

You could add an event to trigger in a business rule on the sys_attachment table when the current.table_name is u_finance.



var att = new Attachment();
att.setRecord(current);
var fin = new GlideRecord('u_finance');
fin.addQuery('sys_id','=',current.table_sys_id);
fin.query();
while (fin.next()){
gs.eventQueue('attachment_added', fin, fin.assigned_to, fin.caller_id);
}


Then create a notification triggered on the attachment_added event and send to event parameter 1 to send it to the assigned to.


Hi David,



I just wanted to let you know that this post solved a major issue for me. Thank you!



John


KingSukh
Tera Expert

That is what i have done, however it does not work quite eloquently for the delete side. The delete side generates a warning due to the deletion happening before the event is fired even though the business rule is a Before Delete Business Rule on sys_attachment. I am trying to figure out what object i can pass in the gs.eventQueue call such that there will be no warning in the log and have a clean build. The aref line is not passing in correctly in the blog but it is correctly formatted in the code as an aref so that i can email a link to the user.

updateRecordForAttachment();
function updateRecordForAttachment(){
// Get the Glide Record for either the custom table.
var gr = new GlideRecord(current.table_name);
var message;
var DEBUG = false;
// Get the record id of the record being attached to
if(gr.get(current.table_sys_id)){
if (gr.approval == 'approved') {
// Update the work notes
gr.work_notes = "Attachment: " + current.file_name + " has been deleted.";
message = "Attachment " + current.file_name + " Deleted in " + gr.number;
// Create this reference here because the event is not firing before delete but rather after and is not working as specified in the business rule before delete on sys_attachment so the reference is lost.
var aref = '' + 'Attachment Deleted in ' + gr.number + '';
if (DEBUG) { gs.log("BR: Attachment Deleted aref " + aref);
gs.log("BR: Attachment Deleted WorkNote " + message);}
gr.update();
// Fire the event, using gr is still creating a warning log for this email
gs.eventQueue("attachment.notify",gr,aref,gr.assigned_to.email);
}
}
}


David OBrien
Kilo Guru

What is the warning message you are getting in the log on delete of attachments? Is it still triggering the notification correctly?