Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

what is the error in below grovvy script for post funtion

Prachi Dube May 10, 2023

While moving to in progress, sub-tasks would be created for each application selected in Application Name (multiselect)
Summary: <App_Name> - Subtask
Select List 1 : Value from parent task
Text 1: Value from parent task
Number 1: Value from parent task"

 

 

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

def parentIssue = sourceIssue
int numMarkups

doAfterCreate = {

if (parentIssue.getIssueType().getName() != 'Task')
{return}

if (parentIssue.summary.contains("Markup Master Task"))
{
numMarkups = Integer.parseInt(parentIssue.summary);
}

if (numMarkups >= 50)
{
return
}
else
{
def i = 0
def issueFactory = ComponentAccessor.getIssueFactory()
def subTaskManager = ComponentAccessor.getSubTaskManager()
def constantManager = ComponentAccessor.getConstantsManager()
def issueManager = ComponentAccessor.getIssueManager()

for (i; i < numMarkups; i++)
{
MutableIssue newSubTask = issueFactory.getIssue()
newSubTask.setSummary("Markup" + i.toString())
newSubTask.assignee == parentIssue.assignee
newSubTask.components == parentIssue.getComponents()
newSubTask.setParentObject(parentIssue)

newSubTask.setPriorityId(constantManager.getPriorities().find {
it.getName() == "P2" }.id)

newSubTask.setProjectObject(parentIssue.getProjectObject())

newSubTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find{
it.getName() == "Sub-task" }.id) }

}


}
}

1 answer

0 votes
Nic Brough -Adaptavist-
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.
May 10, 2023

Welcome to the Atlassian Community!

Your 

def parentIssue = sourceIssue

is making a nonsense of the script - sourceIssue is not a variable you have any access to in a post-function.

Try removing that line completely, and just using "issue" instead of "parentIssue" when you need to look at the current issue.

Your code is also not looking at the select field, it's taking the number of subtasks from the summary, which, in the real world, is likely to be utter nonsense, it's almost certainly going to be 0 for any issue, so there's no reason the code would go into the loop that creates the sub-tasks.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events