• 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

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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published yesterday in Jira

Mission-critical battery manufacturer fulfills FAA software requirements with Commit Policy Plugin

EaglePicher Technologies is a leading manufacturer of battery systems for diverse industries like defense, aviation, space or medical. As they operate in highly regulated industries, keeping a clear ...

168 views 0 2
Read article

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