Using Flow Designer, add attachment to Send Email Action

Daniel O_Connor
Kilo Guru

Hi all,

I've created a Custom App using Studio, whereby we will receive Weather Warnings from a National Weather provider, and then forward this e-mail onto relevant parties. 

I created an extension of TASK so we can have a record of these weather alerts. The e-mail that we will receive, will contain a PDF attachment, that is the details of the warning.

Through my inbound action, I'm creating a record on my new table, where the PDF will be attached to the ticket.

Through Flow (new module, not legacy workflow) I've been able to spin my flow up pretty quickly. However I see no option to include the attachment from the record, onto the e-mail I'm sending out.

find_real_file.png

Any ideas how I can accomplish this?

  • With Send Email action in Flow Designer, have the attachment from the record included in the generated email 
1 ACCEPTED SOLUTION

Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

Hi Daniel,

 

Bad news is that I don't think there is a OOB functionality for this. Good news are that it's very easy to solve with a custom action. Basically you create you own "copy attachment" action and then you can use that action to copy the attachment from the task record to the email-record that is used to send the email.

 

I made a quick video here for you to see what I'm talking about:

View solution in original post

27 REPLIES 27

Hmm.. gotcha. Didn't think of that, let me think a bit about it and see what we can come up with.

//Göran
Feel free to connect:
LinkedIn
Subscribe to my YouTube Channel
or look at my Book: The Witch Doctor's Guide To ServiceNow

Yeah, I tried to add an action right after the email creation, to put the type to send-ignored and THEN do the attachment copy, but that leaves me exposed to a race condition anyway. And the SN Email API doens't let you set the type or mailbox either... I suppose one solution would be a before insert business rule on the sys_email table, which would set the type to send-ignored based on some setting, and then my Flow would update the type once the attachments are copied?

@Göran Lundqvist FYI this is what I ended up doing:

  1. Add a "Before insert" BR on sys_email, that sets the type to send-ignored if the subject starts with "[HOLD]"
  2. Add functionality to my workflow (ended up going back to workflow...) to send the email with "[HOLD]" at the beginning of the subject line
  3. Copy attachments from req item to email via a script (finding the email by its instance, which is my req item's sys_id, and the subject line starting with "[HOLD]")
  4. Update the attachment record to remove "[HOLD]" from the subject line and set the type to send-ready (though I suppose this step could also be a BR)

One thing I noticed is that the Notification activity in the workflow seems to be async - so I had to add a timer right after, and before my GlideSysAttachment.copy('sc_req_item', current.sys_id, 'sys_email', email.sys_id) block.

Hi Goran

 

Thanks for this solution, it's great!

I tried to implement it in my instance, but I'm doing something wrong and didn't work for me.

Can you help me?

I followed your steps from your video:

My action

find_real_file.png

 

The script section

(function execute(inputs, outputs) {
// ... code ...
  var copyAtt = new GlideSysAttachment();
  	copyAtt.copy(inputs.sTable,inputs.sSysID,inputs.tTable,inputs.tSysID);

})(inputs, outputs);

 

The test result (all green / completed)

find_real_file.png

 

The email record in the sys_email table

find_real_file.png

Some differences between your example and my test (I think isn't the problem):

1. I used the action in a for each loop to send several emails (for each member in a group)

2. In my DEV instance the email sending it's not active

 

What do you think? what I'm doing wrong?

Thanks!

Ariel

Hi Goran

I created a fix script to test it and works fine, but with the action in the flow don't.

My fix script:

var sTable = 'sn_customerservice_case';
var sSysID = '8c160c70dbefe414df8e1a44059619d3';
var tTable = 'sys_email';
var tSysID = '565bfc78db236814df8e1a44059619db ';

var copyAtt = new GlideSysAttachment();
copyAtt.copy(sTable, sSysID, tTable, tSysID);

 

After running it the sys_email has the attachments

find_real_file.png

 

Thanks,

Ariel