Hello, folks!
I need your help
I created 2 mygroovy-scripts as post functions:
the first one creates a subtask (this happens during the transition to the next status);
the second - changes the status of the issue to the next one in order (this happens during the transition to the last status of the subtask) (yes, each subtask has its own workflow).
The problem is that when the transition to the last status of a subtask is made, a new subtask is not created, although the status of the issue changes.
Also the button for switching to the next issue status is active, although the transition has already been completed.
I need the next subtask to be created when switching to the last status of a subtask.
Below I am attaching scripts and a screenshot in this post:
1) First script (for issue workflow):
def constantManager = ComponentAccessor.getConstantsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
// def user = ComponentAccessor.getJiraAuthenticationContext().getUser()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueFactory = ComponentAccessor.getIssueFactory()
def subTaskManager = ComponentAccessor.getSubTaskManager()
def issueManager = ComponentAccessor.getIssueManager()
String IDsubTask = ""
Issue parentIssue = issue
MutableIssue newSubTask = issueFactory.getIssue()
newSubTask.setAssigneeId(parentIssue.assigneeId)
newSubTask.setReporterId(parentIssue.reporterId)
newSubTask.setDescription(parentIssue.getDescription())
if (parentIssue.getStatusId() == '10600')
{
newSubTask.setSummary("Subtask - Backlog")
IDsubTask = "10601"
}
else if (parentIssue.getStatusId() == '11400')
{
newSubTask.setSummary("Subtask - Analysis")
IDsubTask = "10602"
}
else if (parentIssue.getStatusId() == '11401')
{
newSubTask.setSummary("Subtask - Development")
IDsubTask = "10604"
}
else if (parentIssue.getStatusId() == '11402')
{
newSubTask.setSummary("Subtask - Testing")
IDsubTask = "10605"
}
if (IDsubTask != "")
{
newSubTask.setParentObject(parentIssue)
newSubTask.setProjectObject(parentIssue.getProjectObject())
newSubTask.setIssueTypeId(IDsubTask)
def newIssueParams = ["issue" : newSubTask] as Map<String,Object>
issueManager.createIssueObject(user, newIssueParams)
subTaskManager.createSubTaskIssueLink(parentIssue, newSubTask, user)
}
2) Second script (for subtask workflows):
def constantManager = ComponentAccessor.getConstantsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueFactory = ComponentAccessor.getIssueFactory()
def subTaskManager = ComponentAccessor.getSubTaskManager()
def issueManager = ComponentAccessor.getIssueManager()
String IDsubTask = ""
Issue parentIssue = issue.getParentObject()
MutableIssue parentIssueM = (MutableIssue)parentIssue
if (issue.getIssueTypeId() == '10601')
{IDsubTask = "11400"}
else if (issue.getIssueTypeId() == '10602')
{IDsubTask = "11401"}
else if (issue.getIssueTypeId() == '10604')
{IDsubTask = "11402"}
else if (issue.getIssueTypeId() == '10605')
{IDsubTask = "10000"}
if (IDsubTask != "")
{
parentIssueM.setStatusId(IDsubTask)
issueManager.updateIssue(user,parentIssueM,EventDispatchOption.ISSUE_UPDATED,false)
parentIssueM.store()
}
else{
return
}
Screenshot:
