Rich Dennis
Tera Expert

Scenario: A workflow email notification needs to include a PDF document.

  1. I've read several times that the best way to do this is via email notification by "Create Event" Activity, instead of the  "Notification" Activity.
  2. Go to the Catalog Item that runs the Workflow and attach the PDF file to it.
  3. Register the new Event.
  4. Create an Email Notification:
    1. that will "Send when" [Event is fired]
    2. "Event parm 1 contains recipient" is checked.
    3. "Message HTML" has a mail script in it like ${mail_script:attach_file}
  5. Create a Notification Email Script that includes the following code:
    // attach file
    	var gr_sys_att = new GlideRecord('sys_attachment');
    	gr_sys_att.addQuery('file_name',"File_Name.pdf");
    	gr_sys_att.addQuery('table_name',"sc_cat_item");
    	gr_sys_att.addQuery('table_sys_id',"b7cffa9d4f58db8031a28b8d0210c75b"); // sys_id of the Catalog Item that the file was attached to earlier.
    	gr_sys_att.query();
    	while (gr_sys_att.next()) {
    		var content = new GlideSysAttachment().getContentStream(gr_sys_att.sys_id);
    		new GlideSysAttachment().writeContentStream(current, gr_sys_att.getValue('file_name'), gr_sys_att.getValue('content_type'), content);
    	}
  6. Note: I found through trial & error that this code block had to be before the last template.print() statement. If its not then the code never ran.

 

Dog Tax: This is Radley.

find_real_file.png

Version history
Last update:
‎10-22-2018 11:22 AM
Updated by: