Get latest Attachment name and author through JIRA Automation

Pierre Ibrahim April 9, 2024

Hello all,

I'm trying to create a JIRA automation that would add a comment whenever an attachment is added, the comment should have the latest attachment's filename and author name.

I've tried using {{attachment.filename.last}} but that brings the last attachment in the list of attachments, which is sorted alphabetically, so that's not very useful.

However I've had success with {{attachment.created.max}} in accessing the latest added attachment, but I can only get the created date. How can I get the filename and the display name for the author from {{attachment.created.max}}?

2 answers

1 accepted

1 vote
Answer accepted
Kalyan Sattaluri
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.
April 9, 2024

Hello @Pierre Ibrahim 

You could use  {{changelog.Attachment.toString}} to get the list of latest attachment's filenames, but I dont think displayName is accessible such way unfortunately.

If your rule trigger is "Field Change" on attachment, then you could use {{initiator.displayName}} cause thats the user who is uploading the docs.

BTW, {{attachment}} smart value gives you the full list of attachments sorted by Alphabetical order, so yes you could find the latest date as you have, but it does not help us to get the corresponding filenames or displayNames since we cannot use it for lookup.. so for your use case, that smartvalue will not help.

Hope it helps and if it works, consider accepting solution so it benefits others in the future. Thanks!

Kalyan Sattaluri
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.
April 9, 2024

...

Pierre Ibrahim April 9, 2024

Hi @Kalyan Sattaluri 

That worked great! Thank you!

Like Kalyan Sattaluri likes this
0 votes
Bill Sheboy
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.
April 9, 2024

Hi @Pierre Ibrahim

With the answer from  @Kalyan Sattaluri you have a solution for all of the current attachments using {{toString}} from the changelog.

It is possible to get the single attachment's details added, as each attachment is added, using a rule triggered on Issue Field Updated for Attachment and quite a few variables and dynamic regular expressions to search with the match() function.  If you still need that, please let me know and I will post the details.

Kind regards,
Bill

Helle Friis Pedersen
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 30, 2024

Hi  @Bill Sheboy ,  

I am working on an automation which should add a comment when an attachment is added, and the comment should preferably contain a link to that last added attachment. So I would like to see the details for the solution you suggest :-)

Best regards, Helle

Bill Sheboy
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 30, 2024

Hi @Helle Friis Pedersen -- Welcome to the Atlassian Community!

I am working on an article on searching list fields, such as attachments; until I post that...

It seems a "simpler" workaround is possible as the changelog can now return just the added attachment's identifier.  And so a REST API function may be called with the Send Web Request action to get the attachment's metadata, including the name, URL, etc.

Here is the rule outline:

Here is a how-to article for calling a REST API function from an automation rule: https://community.atlassian.com/t5/Jira-articles/Automation-for-Jira-Send-web-request-using-Jira-REST-API/ba-p/1443828

Kind regards,
Bill

Helle Friis Pedersen
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 14, 2024

Hi @Bill Sheboy

Thank you so much! The coming article on searching list fields sound really interesting!

Thank you for outlining the automation rule. I will look into this to see if I am able to create the automation I need.

By the way, do you know if it is possible to "catch" the event that an attachment is added via a workflow screen? The trigger on field value added for Attachments seems to only work for attachments added directly to the issue screen. 

Best regards, Helle

Bill Sheboy
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.
June 14, 2024

Sorry, I do not know that. 

You could experiment with a Jira site webhook on "attachment created" and intercept that with a webhook trigger.  That should confirm if attachment added on the workflow screen sends the event.  To try this, create the rule first to get the webhook URL and then use that when setting up the site webhook.

Suggest an answer

Log in or Sign up to answer