Merge user fields into one field to avoid OR filter


We use different fields for users who have interests in an issue. The reporter, the assignee and a costume Multi User Picker field named "Stakeholders".

Now we build filter for all issues currentUser has an interest in.

To filter this we need JQL

(reporter = currentUser() OR Stakeholder = currentUser() OR assignee = currentUser())

But with the OR in our JQL query it is impossible for our customers to use the basic filters and they have no idea to extend our filter.

Now we want to merge (by a plugin, or jelly script?) the reporter, the assignee and the stakeholder into one hidden field, which we can use to filter without or.

Is this possible? has anyone tired something like that and has a hint for use how we get started?

2 answers

1 accepted

2 votes
Accepted answer

I've done something similar for a totally different reason.

As you say, you create a multi-user-picker field, and don't put it on any view screens (it still needs to have the right context for the project and not be hidden in the field context). You then find/write a listener that picks up changes on the fields and rebuilds that hidden field in the background.

Another option, probably a lot more neat, would be to create a derived or scripted field (again, mostly hidden). If you look at the Jira Toolkit plugin, you'll see that has a field for "participants" which is "commenters, reporter and assignee". That's easy to change to "people listed in other user picker fields". I believe you can do it with a scripted field as well, if you have the script-runner plugin.

A calculated field of some type is easy too, only disadvantage is that you need to do a full reindex, and it wastes a bit of storage index space, compared to writing your own jql function.

Yes, a JQL function is another excellent solution, I should have thought of that.

Go on then, give me a vote up, I just gave you one!

Several different options you could use. You could create your own jql function that does this using script runner.

Then you could run a query like:

issueFunction in isStakeholder() and project = "Some Project"

It's not too hard, the code is below. You just paste it in, give your function a description, and that should be it.

package com.onresolve.jira.groovy.jql

import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.index.DocumentConstants
import com.atlassian.jira.jql.query.QueryCreationContext
import com.atlassian.jira.jql.validator.NumberOfArgumentsValidator
import com.atlassian.jira.util.MessageSet
import com.atlassian.query.clause.TerminalClause
import com.atlassian.query.operand.FunctionOperand
import org.apache.lucene.index.Term

class StakeHolderFunction extends AbstractScriptedJqlFunction {

    private static final String STAKEHOLDER = "Stakeholder"
    def customFieldManager = ComponentAccessor.getCustomFieldManager()

    MessageSet validate(User user, FunctionOperand operand, TerminalClause terminalClause) {

        def messageSet = new NumberOfArgumentsValidator(0, 0, getI18n()).validate(operand)

        if (! customFieldManager.getCustomFieldObjectByName(STAKEHOLDER)) {
            messageSet.addErrorMessage("Could not find $STAKEHOLDER field")

        // todo: other validation

    Query getQuery(QueryCreationContext queryCreationContext, FunctionOperand operand, TerminalClause terminalClause) {

        def stakeholder = customFieldManager.getCustomFieldObjectByName("Stakeholder")

        def booleanQuery = new BooleanQuery()
        def currentUser = queryCreationContext.user?.name
        booleanQuery.add(new TermQuery(new Term(DocumentConstants.ISSUE_AUTHOR, currentUser)), BooleanClause.Occur.SHOULD)
        booleanQuery.add(new TermQuery(new Term(DocumentConstants.ISSUE_ASSIGNEE, currentUser)), BooleanClause.Occur.SHOULD)
        booleanQuery.add(new TermQuery(new Term(stakeholder.getId(), currentUser)), BooleanClause.Occur.SHOULD)

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,943 views 19 22
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