Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to get an attachment from a subtask closing screen and send it to main ticket?

Germain Vincent February 2, 2018

Hi everybody,

 

For an internal project, I'm using two workflows, one for the resolution of the main ticket and one for the resolution of the many subtasks that can be created during the main ticket resolution process.

When I close a subtask, I have a screen with an attachment field allowing the user to add an attachment.

I would like to get this attachment and send it to the attachment field in the main ticket.

Actually, when a file is attached on the attachment field of the "close subtask" transition screen the attachment goes nowhere. Neither in the closed subtask and neither in the main ticket...

Does anyone got an idea on a post script function I can use to get this attachment?

 

I'm using script runner 5.1.6 and JIRA 7.2.0

 

Thanks in advance!

 

Regards,

 

Germain.

 

1 answer

1 accepted

1 vote
Answer accepted
Ivan Tovbin
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.
February 2, 2018

Hi Germain,

I might be able to help you here. Can you please clarify, if you want to copy just the attachment that has been added during the 'Close issue' tansition, or all attachments (including this one) that has been accumulated in the sub-task up until this point?

Ivan Tovbin
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.
February 2, 2018

Based on your description, the attachment added during the 'Close issue' transition is always the last one (unless you have any post functions/automation that adds more attachments after that), the code to copy it to the parent issue is as follows:

import com.atlassian.jira.component.ComponentAccessor

def attMgr = ComponentAccessor.getAttachmentManager()
def attachments = attMgr.getAttachments(issue)
def lastAtt = attachments[0]
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

if (attachments.size() > 1){
for (int i = 1; i < attachments.size(); i++){
if (lastAtt.getCreated().getTime() < attachments[i].getCreated().getTime()){
lastAtt = attachments[i]
}
}
}

attMgr.copyAttachment(lastAtt, currentUser, issue.getParentObject().getKey())

 Also, make sure that you place this post function AFTER the "Re-index an issue to keep indexes in sync with the database" post function

Germain Vincent February 2, 2018

Hi Ivan,

 

Thanks a lot for your quick answer!

To clarify, I only want to copy the attachment that has been added during the 'Close issue' tansition.

I will try your code in the afternoon.

 

Thanks again!

Ivan Tovbin
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.
February 2, 2018

Great, tell me if it'll solve your issue.

Please keep in mind though, that this code assumes that:

a) you add only ONE attachment during the transition

and 

b) No other attachments are added as a result of this transition (either through automation or other post functions)

Germain Vincent February 2, 2018

Ivan,

When I'm adding the attachment on the "close subtask" transition screen it doesn't works but if I add the attachment in the subtask before closing it, it works like a charm :)

Do you have any idea on how to get the attachment added during the close transition?

Thanks!

Ivan Tovbin
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.
February 2, 2018

Does the attachment itself get added to the subtask if you add it during the transition? Also, can you post a screenshot of your transition screen? 

Cheers.

Germain Vincent February 2, 2018

unfortunately not

Ivan Tovbin
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.
February 2, 2018

Can you post a screenshot of your transition screen?

Ivan Tovbin
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.
February 2, 2018

Also, please check if you can manually add attachments when your sub-task is in 'Closed' status. If you can't then it probably means that you don't have the permission to do so, while an issue is in that status. To check if it's indeed the case go to your workflow and check the status properties for your 'Closed' status. See if there are any properties there that might prevent you from adding attachments.

Germain Vincent February 2, 2018

Thanks Ivan! Unfortunately I will not be able to check that immediately. I will advice you when done.

Germain Vincent February 2, 2018

I was not allowed to modify a closed subtasks due to a properties.

Now it works!

Ivan, you are a genius :)

Many thanks that's pretty cool for my project!

 

Best regards!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events