Get latest Attachment name and author through JIRA Automation

Pierre Ibrahim
Contributor
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}}?

3 answers

1 accepted

2 votes
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
Contributor
April 9, 2024

Hi @Kalyan Sattaluri 

That worked great! Thank you!

Like Kalyan Sattaluri likes this
0 votes
Milo van Loon October 15, 2024

Hi @Pierre Ibrahim You had an accepted answer, but I did it by using the advanced branching:
lastestfile.png

So, I grabbed the created date of the file added by implementing {{attachment.created.max}}.
Then I made an advanced branch on the attached files of the issue.

I created a smart value out of the created date of the file iterated and compared that to the created date of the file that was in the variable of addedFileCreatedDate.
That condition should then fire only once (provided you did not add the same file twice, but I think the created date is when it was aded to the Issue). 

Weirdly enough the created variable in the loop isn't accessible outside the loop. I'm still trying to find a way around that.

Hope this helps.

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.
October 15, 2024

Hi @Milo van Loon -- Welcome to the Atlassian Community!

Branches which could be on more-than-one-thing are run in parallel and asynchronously, with each item in a separate processing space.  And so any variables created / changed in such branches are gone when that item finishes processing.

And...there is no guarantee of when such branches will finish processing, up until the last step of the rule.

Putting those things together, it is not possible to solve the scenario as you have shown.

 

There are several approaches described in this thread, and another one is to use a dynamic search by de-serializing the attachment data to perform the search: https://community.atlassian.com/t5/Automation-articles/Automation-concepts-Dynamic-searches-within-a-list/ba-p/2834235

 

Kind regards,
Bill

Milo van Loon October 16, 2024

Hi @Bill Sheboy,

You would be correct If I was comparing the looped data with a value that I retrieve after the loop. But I'm comparing it with a value that I captured before the loop. And then it will just compare it in an if block.
Adding the data in this if block will result in consistent data. Provided you keep within the loop and within the If block.

As I can see in the log of the rule, the loop is always ran after the fetch of the variable data.

I could do a re-fetch of the data in the beginning to be absolutely sure.  But as far as I can see the rules fires consistently.

Kind regards,

Milo

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 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 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.

Helle Friis Pedersen June 18, 2024

Thank you for that suggestion, I will try to do that. 

Suggest an answer

Log in or Sign up to answer