Subtask Creation failed in mid multiple story creation

Piyush_Annadate February 17, 2020

Case: Trying to create multiple story when an Epic is getting created. 1 of the story required subtask too.

Success: Multiple Story are getting created and getting linked to it's Epic

Issue: Code checks that if Story 'Complete Security Compliance' is created - it goes to the new block wherein it tries to create Sub-Task and list of summary. Below doesn't create Subtask and also next-in-line Story also doesn't get created.

Help Required:

1. Failure to create the Subtask and why?

2. How to clean the below code?

3. ScriptRunner doesn't show any log.debug and log.info while checking the last run (Script Listener tab)

4. How to use try/catch here?

 

Thanks in Advance !!

 

import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Logger
import org.apache.log4j.Level
import org.apache.log4j.Category
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue

//define debug logs
def Category log = Category.getInstance("com.onresolve.jira.groovy")
log.setLevel(org.apache.log4j.Level.DEBUG)
def issueManager = ComponentAccessor.getIssueManager()
def issueService = ComponentAccessor.getIssueService()
def userManager = ComponentAccessor.getUserManager()
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def constantsManager = ComponentAccessor.constantsManager


def issue = event.issue //user issue
//log.debug(issue.priority.name)
if (issue.issueType.name=='Epic')
{
//log.debug (issue.issueType.name)
def epicLinkCustomField = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue).findByName("Epic Link")
String keyEpic = ComponentAccessor.issueManager.getIssueByCurrentKey(issue.key)
def project = ComponentAccessor.projectManager.getProjectObjByKey(event.getProject().getKey())
def priority = constantsManager.priorities.findByName(issue.priority.name) ?: constantsManager.defaultPriority
def issueTypeST = constantsManager.allIssueTypeObjects.findByName("Story")
def issueTypeTK = constantsManager.allIssueTypeObjects.findByName("Task")
List storySummary = new ArrayList()

storySummary.add("Write Test Cases")
storySummary.add("Complete Security Compliance")//creates this
storySummary.add("Setup Branch and Job") // this gets fails

for(object in storySummary)
{
def issueInputParameters = issueService.newIssueInputParameters().with {
setProjectId(project.id)
setIssueTypeId(issueTypeST.id)
setReporterId(currentUser.key)
setSummary(object)
setPriorityId(priority.id)
addCustomFieldValue("customfield_10001", keyEpic)
}
// log.debug(issue.key)
def validationResult = issueService.validateCreate(currentUser, issueInputParameters)
assert validationResult.isValid() : validationResult.errorCollection

def issueCreateResult = issueService.create(currentUser, validationResult)
assert issueCreateResult.isValid() : issueCreateResult.errorCollection
// def issueNow= issueCreateResult.getIssue().getKey()


//For Subtask Creation fo the Particular story
log.debug(issueCreateResult.getIssue().getKey())
if (object=="Complete Security Compliance")
{
def parentIssue= issueCreateResult.getIssue() //get the Story as issue wherein that stories to have subtask in it.
List subtaskSummary = new ArrayList()
subtaskSummary.add("SAS Survey Completion")
subtaskSummary.add("File OSRB")
for(objectX in subtaskSummary)
{
issueInputParameters = issueService.newIssueInputParameters().with {
setProjectId(project.id)
setIssueTypeId(issueTypeTK.id)
setReporterId(currentUser.key)
setSummary(objectX)
setPriorityId(priority.id)
setParentObject(issueNow.getId())
}
validationResult = issueService.validateCreate(currentUser, issueInputParameters)
assert validationResult.isValid() : validationResult.errorCollection

issueCreateResult = issueService.create(currentUser, validationResult)
assert issueCreateResult.isValid() : issueCreateResult.errorCollection
}

}
}
}

 

Below is the Execution Information from the tab:

The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.

2020-02-17 05:55:18,022 DEBUG [groovyrunner.spring]: BeforeInstantiation [bean=com.onresolve.jira.groovy.GroovyFunctionPlugin, type=com.onresolve.jira.groovy.GroovyFunctionPlugin]
2020-02-17 05:55:18,024 DEBUG [groovyrunner.spring]: AfterInitialisation [bean=com.onresolve.jira.groovy.GroovyFunctionPlugin, type=com.onresolve.jira.groovy.GroovyFunctionPlugin]

 

1 answer

0 votes
Piyush_Annadate February 17, 2020

@Nic Brough -Adaptavist-  Hi. Can you help here?

Suggest an answer

Log in or Sign up to answer