Hello everyone,
I try to automatically create 3 subtasks at the creation of a specific issue type.
These subtasks are going to be call A,B and C.
I need A to blocks B and C.
I use ScriptRunner and I created the three subtasks using the "Create a subtask" post function of script-runner without any problem in the creation transition.
Now the linking part get me frustrated.
I tried to put it in several places:
- In the additional issue actions of both B and C
- In a postfunction in the workflow of both B and C (creation transition)
- As a postfunction in the parent function after postfunction "Create a subtask"
It nevers works. When I get the parent issue object and ask for the lists of objects of subtasks (using issue.substasksObjects) it always giving me an empty list.
I think the substasks or at least the link between subtasks and parents are not in the index at this moment. I think so because the same type of code works well in the console when doing it just after creation of subtasks...
Any idea how to do it?
This is the code I use for the last place I tried (post-function in the parent workflow):
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLinkTypeManager
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def issueLinkTypeManager = ComponentAccessor.getComponent(IssueLinkTypeManager)
def issueManager = ComponentAccessor.issueManager
def subtasks = issue.subTaskObjects
log.debug(subtasks)
def aIssue = subtasks.find{it.issueType.name == "A"}
assert aIssue: "Subtask A can not be retrieve"
def bIssue = subtasks.find{it.issueType.name == "B"}
assert bIssue: "Subtask B can not be retrieve"
def cIssue = subtasks.find{it.issueType.name == "C"}
assert cIssue: "Subtask C can not be retrieve"
def linkType = issueLinkTypeManager.issueLinkTypes.findByName("Blocks")
assert linkType: "Blocks link type can not be retrieve"
ComponentAccessor.issueLinkManager.createIssueLink(aIssue.id, bIssue.id, linkType.id, 0L, loggedInUser)
ComponentAccessor.issueLinkManager.createIssueLink(aIssue.id, bIssue.id, linkType.id, 1L, loggedInUser)
First assert give an error.
Thank you very much for you help