Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Is there a way to add an attachment with automation on Subtask?

Warren McInnes
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 17, 2014

Hi,

I would like to use the script runner post-function to automatically create a sub-task when the main task it created, but for this particular issue type, Is it possible to automatically create the sub-task with an attachment?

I am thinking along the lines of added the attachment (Word.doc) onto the server, then using the script runner to automatically create the sub-task based on a certain issue type, and add the attachment on creation of issue?

Please assist? I'm guessing we would add some groovy

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

4 votes
Answer accepted
JamieA
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 17, 2014

Here is an example for adding an attachment.

import com.atlassian.jira.component.ComponentAccessor

 def attachmentManager = ComponentAccessor.getAttachmentManager()

def user = ComponentAccessor.getJiraAuthenticationContext()?.getUser()

def bean = new CreateAttachmentParamsBean.Builder()
    .file(new File("c:/temp/capture.png"))
    .filename("foobar.png")
    .contentType("image/png")
    .author(user)
    .issue(issue)
    .build()
attachmentManager.createAttachment(bean)

But beware that this API seems to delete the file after it's added, so maybe make a copy of it first.

I'll have a look at your other issue in a bit.

Warren McInnes
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 18, 2014

So we need to look at a method of making a copy of the attachment on the server before adding it to the task if I am correct?

Warren McInnes
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 23, 2014

Hi, Do you have an update for me?

Warren McInnes
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 23, 2014

HI @Jamie,

Would this work?

createAttachmentCopySourceFile

JamieA
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 23, 2014

Is there source code there, I can't see it... answers seems pretty broken atm.

Can you put it on gist.github.comand post the link?

Warren McInnes
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 24, 2014

There is no source code from me,

In this link - https://docs.atlassian.com/jira/6.2.1/com/atlassian/jira/issue/AttachmentManager.html

I found the function called "createAttachmentCopySourceFile" and was wondering if it would work better to copy the file from a source file instead of your example where "API seems to delete the file after it's added"?

Would the code we insert be added to "Post-function > script > create subtask > *Additional issue actions*"?

JamieA
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 24, 2014

OK I see, yeah probably.

> Would the code we insert be added to "Post-function > script > create subtask > *Additional issue actions*"?

yep

Warren McInnes
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 24, 2014

Thanks Jamie,

As per my above query:

Do you know if there any way I could use the options from a Customfield in the summary of the sub-task from the parent issue?

For example:

Nature of Issue:

Option 1(Default): (Issue)

Option 2: (Emergency)

Therefore Main issue summary:

"Implement new server"

Main task auto creates approval sub-task summary:

"(Emergency) Implement new server"

JamieA
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 24, 2014

Can you ask a new question? On the offchance I give a helpful answer, it won't benefit anyone else as they're not going to find it in this question with the answer as is.

Warren McInnes
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 24, 2014

Thanks Will do so :)

Warren McInnes
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 25, 2014
0 votes
JamieA
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 17, 2014

It's simple enough...:

com.atlassian.jira.issue.AttachmentManager#createAttachment(java.io.File, java.lang.String, java.lang.String, com.atlassian.crowd.embedded.api.User, com.atlassian.jira.issue.Issue)

Get the attachManager from ComponentAccessor in the normal way.

The new way is com.atlassian.jira.issue.AttachmentManager#createAttachment(com.atlassian.jira.issue.attachment.CreateAttachmentParamsBean), but optional...

Warren McInnes
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 17, 2014

Sorry Jamie, I am not well versed in this.

Would I add the above code in "Additional issue actions" using built-in scripts > Create sub-task? And where would I add the path to the file?

Sorry secondly is there any way I could use the options from a Customfield in the summary of the sub-task from the parent issue?

For example:

Nature of Issue:

Option 1(Default): (Issue)

Option 2: (Emergency)

Therefore Main issue summary:

"Implement new server"

Main task auto creates approval sub-task summary:

"(Emergency) Implement new server"

Thanks for your assistance

TAGS
AUG Leaders

Atlassian Community Events