Jira expression to validate issues in a certain Status

Nick August 24, 2022

Dear Community!

I'm looking at JWME and ScriptRunner plugins now and trying to make a validator that will block the transition if the project already has tasks in a certain status.

The idea is:
If the task is "In progress" and the assignee is "A", then it is no longer possible to transfer the second task "In progress", where the assignee is "A".

But I can't understand how you can check the number of tasks in the project, and even more so with a specific assignee.

Is there such a possibility? Maybe there are third-party plugins that allow you to do this validator during the transition?

In the Jira expression examples I could not find something similar(

Thanks in advance!

2 answers

0 votes
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.
August 25, 2022

Hi @User ,

I believe what you want is going to be hard to do in Cloud, at least with one of the workflow apps.

As you already know, all the apps use Jira Expressions under the hood, which means – at least up to a point – they are interchangeable when it comes to what can be done with Conditions/Validators.

Now, if I'm not mistaken, you want to effectively stop a user from having more than X open and assigned to them at any given point in time. This implies that you'll need to get a list of all open issues assigned to the user while the Jira Expressions is evaluated. Unfortunately, there is no way to load JQL queries in Conditions/Validators, so the straight up approach won't work.

I see two potential ways you could still achieve your goal, one is rather brittle and the other one has some programming effort. Neither would need an additional app, if you already have JMWE/Scriptrunner.

Option 1 – Using entity properties

Using a post function or an automation, set an entity property on the user with the amount of open assigned issues for that user whenever an issue is assigned/unassigned to that user or an issue that is assigned to the user change its status.

You can use that entity property in your Jira Expression to check on the amount of already open issues. 

Option 2 – Custom Forge App

Atlassian's Forge platform is not just for app vendors, it's also a great fit for scripting and customizing a Jira instance. It has a workflow validator module that can execute a lambda in order to validate a transition. You could use that to check the amount of open issues a user has using some JavaScript and a JQL query, pretty much like what @Tim Chen suggested, but it would work on Cloud. 

Personally, I would go with the Forge option, but you should be comfortable with JavaScript. 

Hope that helps,
 Oliver

Nick August 25, 2022

Hi @Oliver Siebenmarck _Polymetis Apps_ 

Thanks for your answer!

Very good point about properties. I tried a similar process at the beginning with automation with field changes, but I was fluded with notifications about changes in issues.
If we can use properties, then there are no notifications, that's cool!

I tried on automation, everything determines as it should.

But how now to bring the verification of this property into the workflow? I did not find a similar function in the validator or conditions.
Faced with a similar question, can you direct?

For example:

{{issue.properties.assignee_A_work}}

Screenshot_10.png

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.
August 25, 2022

Hi @User ,

Oh, the expression part is pretty straight forward, thankfully. I believe the user object is already filled in the context, meaning you can simply access it:

user.properties

That should give you access to the properties set on that user which you can then check as any other set of attributes. See also here: https://developer.atlassian.com/cloud/jira/service-desk/jira-expressions-type-reference/#user

So something like this maybe:

user.properties.assignee_A_work < 1

Hope that helps,
 Oliver

 

Edit: Just noticed that you're setting an issue property in your automation. You'll want to store the information on the user, not the issue. 

0 votes
Tim Chen August 24, 2022

You can create a scriptrunner validator and add it into all transitions that from to-do to in-progress.

 

The validator script might be like:

// custom script validator
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.opensymphony.workflow.InvalidInputException

def current_user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def query = /assignee = currentUser() and project = "$issue.projectObject.name" and statusCategory = "In Progress"/ // searching for current user having in-progress issues in current project
def jql = ComponentAccessor.getComponent(JqlQueryParser).parseQuery(query)
def page_filter = new PagerFilter(1) // 1 = search only 1 issue

def in_progress_issues = ComponentAccessor.getComponent(SearchService).search(current_user, jql, page_filter)

if(in_progress_issues){ // exist at least one in-progress issue
invalidInputException = new InvalidInputException("VALIDATION FAILED MESSAGE YOU WANT")
}else{
true // true = validation is pass
}

I haven't test this code, but you can still try it.

Suggest an answer

Log in or Sign up to answer