Hi,
Has anyone successfully created a subtask on the Create transition and subsequently linked it to its parent issue automatically in the same transition with a script?
I'd really appreciate if you'd share how this can be done
Thanks,
Connor
Hello Connor.
I believe this can be done with the SR Create Subtask post function.
Since it is a sub task, it needs to have a parent, so if you were to add this post-function in te onCreate transaction, it would create the subtask that you are looking for.
This is the dialog that you need to fill, and it can be accessed in the add postfunction dialog in the workflow transaction editor.
If you have more questions do not hessitate to ask.
Cheers!
Dyelamos
Dyelamos,
Thank you for the reply! I'm already able to create subtasks through this exact dialog- my question is how I can configure this dialog so that upon creation the subtask will be 'linked' to the parent issue - do you know how I could configure that?
Thanks a lot
Isn't that done automatically? When I create a subtask it links the parent on its own
That's a good point - a sub-task is always part of its parent and displays as such. The fact it is a sub-task means there is a link to the parent.
Creating an issue link as well is redundant (although if you looked at the code, you'd see an invisible "system" issue link is already there)
Here´s how I did it using Script Runner:
Using a ScriptPost Function, at the end of the create transition:
import com.atlassian.jira.ComponentManagerimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.MutableIssueimport com.atlassian.jira.issue.link.IssueLinkTypeManagerimport com.atlassian.jira.issue.util.DefaultIssueChangeHolderimport com.atlassian.jira.issue.util.IssueChangeHolderimport com.atlassian.jira.issue.ModifiedValueimport groovy.util.logging.Log4jimport org.apache.log4j.Categorylog.setLevel(org.apache.log4j.Level.INFO)MutableIssue parent = issue.getParentObject() as MutableIssuedef issueManager = ComponentAccessor.getIssueManager(); def projectIssue = issueManager.getIssueObject(parent.id); def isProjectIssueValid = (projectIssue != null); try{ def issueLinkManager = ComponentAccessor.getIssueLinkManager(); log.info "Link being created by " + ComponentAccessor.getJiraAuthenticationContext().getUser() + " - Parent: " + parent.id + " and child: " + issue; issueLinkManager.createIssueLink(projectIssue.id, issue.id, 00000L, 1L, ComponentAccessor.getJiraAuthenticationContext().getUser()); // here you replace "00000" for the ID of the Issue link, keep the "L" after the ID. } catch (Exception e) { log.info e }
Hope this helps.
Hi Danilo,
your script works just fine but it always uses the inward link on the thus created subtasks (child). We use subtasks which "treat" our issues and this needs to be changed around for and specific addon to work properly and show additional informations. What do we need to change to make it work?
Thanks and kind regards
Maik
Hi @Maik Pomp , I'm glad to hear that it worked for you as well. To "invert" the issue link being created, in the line 21, you can just change where you see:
"projectIssue.id, issue.id"
to
"issue.id, projectIssue.id"
This will literally "invert" the link and use the outward link.
Works just fine @Danilo Lima. I added a line so it only works on specific parent tasks (cause we use our treatment subtasks on several issuetypes and i don't want all to be linked (automatically)).
Thanks again
It looks like you're new here. Sign in or register to get started.