Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Jira expression for checking Epic tasks statuses

Gabriel.Goluta February 18, 2022

Hi everyone,

I am not very experienced with jira expressions and I would need your help please.

I am trying to set up a validator to prevent users to close epics if the tasks and stories included in that epic are not done.

I am using Scriptrunner for this, where I need to set a jira expression to validate the statuses. So far, I tried several, just that it doesn't pass the test when I'm doing it:

First option:

issue.isEpic && issue.links.every(s => s.linkedissue.status.name == "Done")

This returns true even if I have an epic with still "in progress" tasks.

Second option:

issue.links.every(s => s.inwardIssue.status.name == "Done")

Same problem, gives me a true response even if the epic has "in progress" tasks.

What am I doing wrong?

2 answers

1 accepted

1 vote
Answer accepted
Oliver Siebenmarck _Polymetis Apps_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 15, 2022

Hi @Gabriel.Goluta ,

The great thing about Jira Expressions is, that they work the same in every app that uses them, they truly are universal. Even though I do not use ScriptRunner Cloud, the following should work for you.

Your first option is actually pretty close. Here's what should work:

issue.isEpic && issue.stories.filter( s => s.status.name != "Done").length == 0

You first want to check whether the issue is an Epic and then check for the Stories in that Epic. However, issue.links does not show the Stories of an Epic, but rather linked issues. That's a difference in Jira, and you should be able to see two sets of links on your Epics. 

Epics have their Stories in an attribute named 'stories'. We can filter that list, so that only those that are not done remain. If that filtered list is longer than 0, some Stories are still open and the Validator fails.

Now, you mentioned Tasks and Stories, but the attribute is simply called 'stories'. Tasks will be included in that list, so the above will work for both.

Hope that helps,
 Oliver 

Gabriel.Goluta March 16, 2022

Thank you very much @Oliver Siebenmarck _Polymetis Apps_ , this is what I was looking for :)
I didn't know that the attribute stories included all the issues belonging to an epic, I was looking for exactly this attribute.

Now, because I usually have extra issue types in an Epic, with a different status, I modified a bit your condition to include those as well:

issue.isEpic && issue.stories.filter( s => !["Done","Released"].includes(s.status.name)).length == 0

So far, after a bit of testing against existing Epics, seems to work fine.

 

Thank you again! 

0 votes
Crystelle S
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 14, 2022

I don't have any help for ScriptRunner.

Is there any reason you aren't using a simple workflow validator in the transition of the Epic to "done"? It's basic but it might be easier.

Suggest an answer

Log in or Sign up to answer