ScriptRunner e-mail post function how to include 2 different file types as attachments

Kimi Nakashima May 19, 2023

In our workflow we have a transition called "Ship product". During this transition an email is sent to our shipping location that has instructions on how to ship a requested product. Included in that email is a shipping label and occasionally if our customer requires it, a cover letter. I wish I could use the include all attachments option but sometimes the issue has attachments other than the shipping label and cover letter like their company logo from their email replies. I don't want those to be emailed to the shipping dept because anything attached to the email will end up printed and included in the package. So since the shipping labels are always pdf files and the cover letters are always Word files, I tried to use the custom option. 

Using the snippet example I was able to get either the pdf to send or the doc file but I couldn't get them both to send and I couldn't figure out how to manipulate it to send them both. Is it not possible?

2 answers

1 accepted

2 votes
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 22, 2023

Hi @Kimi Nakashima

I assume you are using ScriptRunner's Send Custom Email Post-Function for your requirement.

If yes, you can follow the steps below:-

1. First, ensure that you have selected the Custom option in the Include Attachments section.

2. Add the code below into the Custom Attachments Callback field:-

import com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.mail.MailAttachment

{

MailAttachment a ->

def filename = a.filename.toLowerCase()

filename.endsWith('.pdf') || filename.endsWith('.docx') || filename.endsWitch('.doc')

}

Please note that the working custom code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

Below is a screenshot for your reference:-

post_function-1.png

Below are a couple of test screenshots:-

1. In the sample issue, there are a couple of attachments included, i.e. png, pdf and doc file types as shown in the screenshot below:-

ksnip_20230522-174215.png

2. Once the issue transitions to In Progress, the mail is triggered. However in the mail as expected, only the pdf and docx file types are included as shown in the screenshots below:-

ksnip_20230522-174518.png

 

ksnip_20230522-174708.png

I hope this helps to answer your question. :-)

Thank you and Kind regards,

Ram

Kimi Nakashima May 22, 2023

@Ram Kumar Aravindakshan _Adaptavist_ This totally worked! Thank you very much!

0 votes
Ken McClean
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 20, 2023

Can you provide the code you've come up with so far?  It's easier to help you troubleshoot

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
5.7.0
TAGS
AUG Leaders

Atlassian Community Events