is there a way to include attachments on Approval Email Notifications without having to copy them from the "approval_for" reference record ?

Makosko
Tera Expert

For some strange reason, I seem unable to have SN copy attachments from the approval_for reference record to an actual approval request. In my email notification, I have the "Include Attachments" field checked, still no attachments coming through. Is there something else I am forgetting to check ??

Any help with this would be very much appreciated.

32 REPLIES 32

Thanks for the reply.


This is getting me started off in the right place but it is still not working. I think its because i am doing slightly different than you were. What I have is a Catalog Item where i attach a file to that is saved on the RITM (sc_req_item) table i think? Then when that workflow creates an approval single / or group approval i want that file to be auto attached to those approvals.



Here is what I tried with no luck.



Business Rule - Table sysapproval_approver / When Before


Tried Both Insert and Update = I think it should be while the system is inserting it right?



No Conditions - I want this to happen all RITMS that have an attachment that need an approval it will copy to that.



Script - I am such a script novice it must be here the table names wrong or something.



(function(){



if(typeof GlideSysAttachment !== "undefined") {


      GlideSysAttachment.copy('current.sc_req_item.sys_class_name.toString()', 'current.sc_req_item.sys_id.toString()', current.getTableName(),current.getUniqueValue());


} else {


      Packages.com.glide.ui.SysAttachment.copy('current.sc_req_item.sys_class_name.toString()', 'current.sc_req_item.sys_id.toString()', current.getTableName(), current.getUniqueValue());


}



})()




Thanks in advance again> Your awesome.


'current.sc_req_item.sys_class_name.toString()' to become current.sysapproval.sys_class_name.toString() -> no quotes around these statements !


'current.sc_req_item.sys_id.toString()' to become current.sysapproval.sys_id.toString() -> no quotes around these statements !




Final Result: ( do the same for Packages.com.glide etc... )




GlideSysAttachment.copy(current.sysapproval.sys_class_name.toString(), current.sysapproval.sys_id.toString(), current.getTableName(),current.getUniqueValue());




I think your condition is likely to be the following:


current.sysapproval.sys_class_name.toString() == 'sc_req_item' -> make sure that is the actual table name...


Thanks very much for this Makosko - however I noticed when requesting approval, this was causing an update meaning the CHG approval request e-mail had duplicate copies of the attachments on it.



I understand I could make the business rule on insert only but then run the risk of someone attaching files to the CHG after the approvers have been added so is there a way to check in the business rule whether the attachments are already there on the approval record and if not, insert them, otherwise don't?



My BR code is as follows right now:



(function(){



if(typeof GlideSysAttachment !== current.sysapproval.sys_class_name.toString()) {


      GlideSysAttachment.copy(current.sysapproval.sys_class_name.toString(), current.sysapproval.sys_id.toString(), current.getTableName(),current.getUniqueValue());


} else {


      Packages.com.glide.ui.SysAttachment.copy(current.sysapproval.sys_class_name.toString(), current.sysapproval.sys_id.toString(), current.getTableName(), current.getUniqueValue());


}



//table_to_copy_from -> likely to be current.sysapproval.sys_class_name.toString()


//record_id-> likely to be current.sysapproval.sys_id.toString()



})()



Many thanks for any help in advance,


D


ndt13
Giga Expert

Hi Maros,



Did you ever find a solution for this?   I am running into the same issue right now and would like the attachments to be sent along with the approval email notifications.



Thanks


Nthlenda-



Don't know if this will help, but I have had a functioning system in place for a while. I thought i would just spread the help that Marcos and Others helped me with. Below are the business rule and Email template (Note I have our email link hardcoded to our production instance).



Business Rule


Name = Whatever you would like.


Table = Approval


When = Before


Order = 100


Script =


var gr = new GlideRecord('sc_req_item');  


gr.addQuery('sys_id', current.sysapproval);  


gr.query();  


while(gr.next()) {  


Packages.com.glide.ui.SysAttachment.copy("sc_req_item", gr.sys_id, "sysapproval_approver", current.sys_id);  


}



Email Template - Put anywhere inline



<mail_script>



printattachments();



function printattachments() {


      var gr = new GlideRecord('sys_attachment');


      gr.addQuery('table_sys_id',current.sys_id);


      gr.query();


      while (gr.next()) {


              template.print('Click here to view the Attachment: <a href="https://YourInstanceHere.service-now.com/sys_attachment.do?sys_id='


                      + gr.sys_id + '">' + gr.file_name + '</a>\n');


      }


}


</mail_script>