How do I add docx attachments to an e-mail with Automation for JIRA

E Hanumanthu December 19, 2022

Is it possible to add only docx attachments to an e-mail with Automation for JIRA ?

I am able to attach All the attachments by using below. But only the requirement is needs to add docx attachments. Can anyone help me out how to filter docx files from this.

Attachments:

<ul>

{{#issue.attachment}}

<li><a href="{{content}}">{{filename}}</a></li>

{{/issue.attachment}}

</ul>

1 answer

1 accepted

2 votes
Answer accepted
Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 20, 2022

Hi @E Hanumanthu - I think this will do the trick. I had to put it all on one line to avoid Automation adding line breaks in the email:

<ul>
{{#issue.attachment}}{{#if(exists(filename.match("(.*\.docx)$")))}}<li><a href="{{content}}">{{filename}}</a></li>{{/}}{{/}}
</ul>

Basically we are trying to match filenames that end with .docx, and if so, then include them.

I would also suggest that if you aren't already you should probably do a check to make sure that this smart value:

{{#issue.attachment}}{{#if(exists(filename.match("(.*\.docx)$")))}}{{filename}}{{/}}{{/}}

does not equal Empty. (To ensure that you don't send an email if there are not any docx attachments.)

References:

Gnana Sekhar Reddy December 20, 2022

Hi @Darryl Lee 

Is it possible to add Particular file name in attachments to an e-mail with Automation for JIRA 

Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 20, 2022

Hi @Gnana Sekhar Reddy - so if you're asking if you can only include a specific file to the email, yes you would simply change the match() statement above to something like:

... .match("(nameofyourfile\.docx)")

The \ in front of the . is used because . is a "wildcard" character in regular expressions.

Like E Hanumanthu likes this
Gnana Sekhar Reddy December 21, 2022

Hi @Darryl Lee 

But when i am implementing that, getting below error in Audit log(Project Automation), E-mails notification not receiving . Can you help me out from this.

Note: This is file name : MOP-230_Test_1

 

Error rendering smart-values when executing this rule:
Tokens must be separated by '.': ”))): Hi {{issue.approver.displayname}}, {{issue.reporter.displayname}} has been submitted MOP for your Approval. Please approve it. Thank you. The issue: <a href="{{issue.url}}">{{issue.key}} - {{issue.summary}}</a> Attachments: <ul> {{#issue.attachment}}{{#if(exists(filename.match(“(MOP\.docx)”)))}}<li><a href="{{content}}">{{filename}}</a></li>{{/}}{{/}} </ul
Automation Error.jpg
Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 21, 2022

Hi @Gnana Sekhar Reddy -- thank you for including the error message. It was very helpful in finding the problem.

The thing that was breaking your rule is that your quotation marks in the match block are curly quotes, not "straight" quotes.

I replaced the quotes with straight quotes, and it got rid of the error.

HOWEVER your rule will not work as intended unless you add a wildcard (.*) to your match, so it should be:

match("(MOP.*\.docx)")

Also, as with my advice to @E Hanumanthu you probably want to do a check to ensure that there is an attachment that matches what you expect before sending the email.

Screen Shot 2022-12-21 at 9.53.55 AM.png

Like E Hanumanthu likes this
E Hanumanthu December 21, 2022

Hi @Darryl Lee Thank you so much for your valuable information. 


Gnana Sekhar Reddy December 22, 2022

Hi @Darryl Lee Thank you so much for your valuable information. 

Now I have one more requirement. From this below how can we take only latest version document. Just i want latest one i don't want all the documents with that particular name. Can you please confirm me how can we do that.

Note: Documents should be likes this MOP-230_Test_1, MOP-230_Test_2, MOP-230_Test_3.......etc 

<ul>
{{#issue.attachment}}{{#if(exists(filename.match("(MOP.*\.docx)")))}}<li><a href="{{content}}">{{filename}}</a></li>{{/}}{{/}}
</ul>

Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 22, 2022

Hi @Gnana Sekhar Reddy will any attached documents not be MOP documents?

If they are all MOP docs, then you could just grab the .last attachment:

<ul>
<li><a href="{{issue.attachment.last.content}}">{{issue.attachment.last.filename}}</a></li>
</ul>

But I guess if there might be other documents interspersed amongst the MOP docs. Hrm.

This will work:

  • Create variable allfilenames that generates a comma-delimited list of MOP filenames, in order of attachment:
    {{#issue.attachment}}{{#if(exists(filename.match("(MOP.*\.docx)")))}}{{filename}}{{^last}},{{/}}{{/}}{{/}}
  • Create variable allcontents that generates list of MOP content links, in order of attachment:
    {{#issue.attachment}}{{#if(exists(filename.match("(MOP.*\.docx)")))}}{{content}}{{^last}},{{/}}{{/}}{{/}}
  • Update email to use split function to separate out lists of MOP filenames/contents, then use last function to get the last one.
    <ul><li><a href="{{allcontents.split(",").last}}">{{allfilenames.split(",").last}}</a></li></ul>
Like # people like this
Gnana Sekhar Reddy January 12, 2023

Hi @Darryl Lee 

The above 2  are not working. I am getting all the MOP files/Content links. Can you please looking into it. For your reference i am attaching output also. 

1) {{#issue.attachment}}{{#if(exists(filename.match("(MOP.*\.docx)")))}}{{filename}}{{^last}},{{/}}{{/}}{{/}}

2) {{#issue.attachment}}{{#if(exists(filename.match("(MOP.*\.docx)")))}}{{content}}{{^last}},{{/}}{{/}}{{/}}

Even that's not opening format like this below

Email Out put:

Screenshot Email.jpg

 

Email Output:

Screenshot 2023-01-12 180342.jpg

Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 13, 2023

Hi. I think you may not have fully understood my instructions.

It looks like what you included in the email are supposed to be intermediary variables that are later used within the email.

So you need to use the Create variable action to create the variables I mentioned, like so:

Screen Shot 2023-01-13 at 1.42.44 AM.png

Then you will reference those variables in the email, like so:

Screen Shot 2023-01-13 at 1.43.07 AM.png

If you have additional issues, please share a screenshot of your rule.

Gnana Sekhar Reddy January 13, 2023

Hi @Darryl Lee Please find attached Screenshot of my Automation rule.

 

Screenshot Automation rule.jpg 

Gnana Sekhar Reddy January 13, 2023

Hi @Darryl Lee for this below screenshot which new action you took for that( Create Variable).

Screenshot 2023-01-13 172426.jpg

I struck here. Can you please help me out. I am following your steps only.

Screenshot 2023-01-13 172632.jpg

Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 13, 2023

The manual trigger I am using is just for testing.

What you need to do is edit your existing rule and insert the 2 "Create variable" actions after your trigger, and then update the Attachments section of your email to use the code I gave you (that includes the "split" commands).

Gnana Sekhar Reddy January 16, 2023

Hi @Darryl Lee is it possible to attach(Implement smart Values) based on Current Document Version of an Jira issue. For your reference find attached screenshot.

If possible means that could be find so we can easily attach latest version document.

Screenshot 2023-01-16 210110.jpg

Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 16, 2023

I don't think there's a way to use a field value as part of a match function, so no, I don't think that will work.

Again, in my testing, I used the Create variable action to create two variables, and then I referenced those variables in the email, and this seemed to consistently get the most recent attachment.

The screenshot you shared did not contain those actions, nor do I see the check I suggested to ensure that there is in fact a MOP.*\.docx file attached.

Again, I would go back to my previous screenshots and steps that I shared, and make sure you include all the steps. You can't skip any and expect this to work.

Gnana Sekhar Reddy January 17, 2023

Hi @Darryl Lee I am unable to create the Create Variable in Jira Automation. We are using DC Flat form. Is there any option to create that in DC Level. Can you please confirm me.Screenshot 2023-01-17 145834.jpg 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events