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
Community moderators have prevented the ability to post new answers.
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.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, Do you have an update for me?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
HI @Jamie,
Would this work?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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*"?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
OK I see, yeah probably.
> Would the code we insert be added to "Post-function > script > create subtask > *Additional issue actions*"?
yep
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Will do so :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.