Scriptrunner - Issue with transition.

Ashley Thomas May 13, 2019

Hi All,

 

I am trying to resolve the parent, when all the child issues are resolved. 

The log/print statements show that the child issues are all "Done" and the parent can be closed.

The code gets stuck or errors during the validateTransition call.

I do not get any of the exceptions I am trying to catch.

The errorcollection at the end is also empty.

 

When I uncomment the transition() call line, I get an error that says 

NullPointerException: Cannot get property 'key' on null object

 

The currentuser.key has valid value.

 

Any help or pointers on how to debug would be greatly appreciated.

 

Thank you so much for your time !!!

 

 

Here is the snippet of my code (skipped the imports)

 

 

<snip>

Issue issue = issue

 

def issueManager = ComponentAccessor.issueManager

def linkMgr = ComponentAccessor.getIssueLinkManager()

def close_status = 1

def src_obj

 

for (IssueLink link in linkMgr.getInwardLinks(issue.id)) {

    src_obj = link.getSourceObject()

    for (IssueLink link1 in linkMgr.getOutwardLinks(src_obj.id)) {

        def dest_obj = link1.getDestinationObject()

        log.warn("Child: " + dest_obj.key + "," + dest_obj.status.name)

        if (dest_obj.status.name != "Done") {

            close_status = 0

        }

    }

}

 

if (close_status == 1){

    log.warn("Close Parent")

    def issueLinkManager = ComponentAccessor.getIssueLinkManager();

    JiraAuthenticationContext authContext = ComponentAccessor.getJiraAuthenticationContext()

           authContext.setLoggedInUser(ComponentAccessor.getUserManager().getUserByKey("testuser"))

    com.atlassian.jira.user.ApplicationUser currentuser = authContext.getLoggedInUser()

    MutableIssue m_issue = (MutableIssue)src_obj

    MutableIssue p_issue = (MutableIssue) issueManager.getIssueObject(m_issue.key)

    String issuetype   = p_issue.issueType.name

 

    def transition = 171

 

    def issueService = ComponentAccessor.getIssueService()

    def issueInputParameters = issueService.newIssueInputParameters()

    issueInputParameters.setRetainExistingValuesWhenParameterNotProvided(true)

    issueInputParameters.setApplyDefaultValuesWhenParameterNotProvided(true)

    log.warn(issueInputParameters.dump())

      

    def builder = new TransitionOptions.Builder()

              

    log.warn("Validate transition" + ", User: " + currentuser.key)

    log.warn("Validate transition" + ", Issue id: " + p_issue.id)

    log.warn("Validate transition" + ", (M)Issue id: " + m_issue.id)

    log.warn("Validate transition" + ", Transition: " + transition)

    log.warn("Validate transition" + ", Transition: " + issueInputParameters.retainExistingValuesWhenParameterNotProvided)

    log.warn("Validate transition" + ", Transition: " + issueInputParameters.applyDefaultValuesWhenParameterNotProvided)

 

   

    def transitionValidationResult;

    try {

        transitionValidationResult = issueService.validateTransition(currentuser, p_issue.id, transition, issueInputParameters)   

    }

    catch(WorkflowException ex){

        log.warn("Exception:" + ex.getMessage())

    }

    catch(org.ofbiz.core.entity.GenericTransactionException ex)

    {

        log.warn("Exception:" + ex.getMessage())

    }

    catch(Exception ex){

        log.warn("Exception:" + ex.getMessage())

    }

    catch(Throwable ex){

        log.warn("Exception:" + ex.getMessage())

    }

    log.warn("test")

 

    def errorCollection = transitionValidationResult.errorCollection

 

    //issueService.transition(currentuser, transitionValidationResult)

}

 

1 answer

1 accepted

0 votes
Answer accepted
Bunty May 13, 2019

Script is not required:

In parent workflow for resolved status transition add a script runner postfunction:

"Transition parent when all subtasks are resolved"

Ashley Thomas May 13, 2019

Thank you for your answer.

 

That approach worked when sub-tasks were created from an Issue

 

However, that was not working when I created issues from Issues. 

i.e. Parent Issue -> Child Issue

 

Parent Issue -> subtasks ==> "Transition parent when all subtasks are resolved" works !

Parent Issue -> Child Issue ==> "Transition parent when all subtasks are resolved" does not work.

 

Is that post script meant to handle both these scenario?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events