The Zurich release has arrived! Interested in new features and functionalities? Click here for more

How to add an attachment to an email vial script

Mark94
Kilo Expert

Hi,

I have a workflow, that having done bits and bobs creates a PDF file, and attaches it to the ticket (a purchase order ticket). The next step I have been asked to build is to attach that PDF to an email and send it externally.

I've tried one method which was detailed in another post -

Attempt 1 -

1. Go to System Notification > Email > Notification Email Scripts
2. Create email script called 'attachfile'
3. Add this line to the script -    
template.print('Attachment: <a href="sys_attachment.do?sys_id=b32dec79db2dd450c646f5461d9619d6">Attachment</a>');
4. Add the following line to the workflow's Notification step in the message -
${mail_script:attachfile};

Sadly, this only adds a link to the PDF, and doesn't attach it to the email (I hard coded the sys_id only as a test).

 

Attempt 2 -

I've started to create a script inside the workflow. This was again taken from another post.

var gr = new GlideRecord('sys_attachment');
  var table = '';
  gr.addQuery('table_sys_id',current.instance);
  gr.query();
  while(gr.next()) {
      table = gr.table_name;
  }
  if (table != '') {
      GlideSysAttachment.copy(table,current.instance,'sys_email',current.sys_id);
      gs.print('Creating attachment');
  }
 

I've now got a bit stuck, I'm not sure where to go from here. This in itself isn't doing anything, and I'm not sure if it's going to. Can anyone point me in the right direction. Am I on the right track?

Many thanks,

Mark.

1 ACCEPTED SOLUTION

Mark,

Excellent, yes please see the attached for 5.4 & 5.41 which shows the setup.

Please let me know once this is working, otherwise please feel free to show your setup and happy to compare.

 

Kind regards

Steve

View solution in original post

16 REPLIES 16

SW7
Giga Guru

Mark,

I use flow designer to perform these actions and really flexible. Let me know if you want to create this in Flow designer and I can send you the details through. 

Kind regards

Steve

 

 

Hi Steve,

Thanks. I've created a Flow (my very first!), and it triggers and sends an email. However, I still can't find a way to copy the attachment in the ticket to the email.

My flow currently has just one trigger, and one action - the action being "Send Email".

If you have some details to assist, that would be awesome.

Thanks,

Mark.

 

Mark,

Congratulations on the first flow. The way i created this same flow was in flow designer, which is really a simple process, happy to share if you do want to use this. That's the way I know and use, so cant really help with the way you are scripting this currently.

Kind regards

Steve  

Hi Steve,

I used Flow Designer to create this new flow. It was very simple, but I don't know how to add an attachment in my "Send Email" step.

Kind Regards,

Mark.