Hi,
I'm trying to implement a JQL Script via ScriptRunner but I not able to find the right query.
I know how to inlcude my JQL Script (thanks to Jamie Echlin for inlcuding it via ScriptRunner) and it works fine if I use a query from Jamie's examples .
But I'm not able to write a query that says "value of a property of currentuser = value of a custom field".
Sounds simple, but I'm not familar with this apach lucence search stuff.
Below is my code. Maybe you can help me on the query.
Background:
I've the organization of the (current) user in his property from an active directory sync. The organization of the assignee is available in a custom field.
So with the query "MyOrganization" I want to get all issues of my organization.
Thanks Dieter
package com.onresolve.jira.groovy.jql import com.atlassian.crowd.embedded.api.User import com.atlassian.jira.ComponentManager import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.link.IssueLinkTypeManager 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 import org.apache.lucene.search.Query import org.apache.lucene.search.TermQuery import com.atlassian.jira.user.ApplicationUser; import com.atlassian.jira.user.UserPropertyManager import com.opensymphony.module.propertyset.PropertySet; import com.atlassian.jira.component.ComponentAccessor import org.apache.log4j.Category public class MyOrganization extends AbstractScriptedJqlFunction implements JqlQueryFunction { def String subquery @Override String getDescription() { "gets open issues of my organization" } @Override List<Map> getArguments() { } @Override String getFunctionName() {"myOrganization"} @Override MessageSet validate(User user, FunctionOperand operand, TerminalClause terminalClause) { def messageSet = super.validate(user, operand, terminalClause) //subquery = "project = '" + "VIR" + "'" //messageSet.addMessageSet (validateSubquery(user, subquery)) messageSet } Query getQuery(QueryCreationContext queryCreationContext, FunctionOperand operand, TerminalClause terminalClause) { UserPropertyManager userPropertyManager = ComponentAccessor.getUserPropertyManager(); //def currentUser = queryCreationContext.user?.name ApplicationUser appUser = queryCreationContext.getApplicationUser(); PropertySet ps = userPropertyManager.getPropertySet(appUser); def Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction"); log.setLevel(org.apache.log4j.Level.DEBUG); log.info("My property to check:" + ps.getString("my.organization")); /* ----- Thats the query of the example of scriptrunnner (searching for --- def query = ..... here I need helpt for a query that checks if my property is equal to a value of a given custom field .... */ } }
I
Community moderators have prevented the ability to post new answers.
Hi Dieter,
https://scriptrunner.adaptavist.com/latest/jira/jql-functions.html#_issuefieldmatch (if you want to compare String values) or you can use https://scriptrunner.adaptavist.com/latest/jira/jql-functions.html#_expression if you want to compare Numbers or Dates
Please let me know if these links helped you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.