• Community
  • Products
  • Jira
  • Questions
  • How do I write a groovy expression for my workflow post-function? (Only run transition when all stories of the epic = "Done")

How do I write a groovy expression for my workflow post-function? (Only run transition when all stories of the epic = "Done")

Hi All,

i am new to groovy. can someone help me with a script for post function that will do the following.

when moving story to done, change the story parent epic to done as well if all the stories that belong to the parent epic are also in done.

thanks in Advanced,

Erez

1 answer

This widget could not be displayed.

Here're the steps:

  1. Add post-function to transition the issue
  2. In the post function check if all the stories of the parent epic are done - use JQL to find these stories
  3. If the condition is true execute the code to transition the issue

Use the samples below to construct your own script.

 

Sample of running JQL query and iterating the results:

Use this to create a check of all stories in epic are Done. The JQL should be something like

"Epic Link" = issue.parent.key
package examples.docs
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
 
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser.class)
def searchProvider = ComponentAccessor.getComponent(SearchProvider.class)
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getUser()
 
// edit this query to suit
def query = jqlQueryParser.parseQuery("project = JRA and assignee = currentUser()")
def results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter())
 
results.getIssues().each {documentIssue ->
    log.debug(documentIssue.key)
 
    // if you need a mutable issue you can do:
    def issue = issueManager.getIssueObject(documentIssue.id)
    // do something to the issue...
    log.debug(issue)
}

 

Sample on how to transition issue with groovy

Use the com.onresolve.scriptrunner.canned.jira.utils.WorkflowUtil helper to transition the parent if the condition is true

/**

     * Transitions the issue. If it fails, the errorCollection should have some deep validation on why it failed, but this is also logged

     *

     * @param additionalScript

     * @param theIssue

     * @param actionId

     * @param user

     * @param scriptParams

     * @return an IssueResult

     */

    public static IssueService.IssueResult actionIssueWithFeedBack(String additionalScript, MutableIssue theIssue, Integer actionId, User user, Map scriptParams = [:]) {

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted yesterday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

76 views 1 0
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you