Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Scriptrunner - Issue with transition.

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

Script is not required:

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

"Transition parent when all subtasks are resolved"

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
Community showcase
Published in Apps & Integrations

Send an Email or Publish to Confluence - What should you do with your release notes?

Background When you hear the words ‘Release notes’, almost always you think of an unsolicited email from a software vendor. But I am here to tell you that from our data, sending release notes via E...

136 views 1 2
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you