I want to use the IN oprator but this RTC Code field does not support. How i can use it? Thanks a lot!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Sid ,
I want to write a custom JQL function.
Here is the scenario,
We have custom field call 'Feature' in epic issue create/edit/view screen. Feature is an issue search field. User will select the feature while creating an epic. So, There will be a chance where more than one epic will have same feature set.
In the Feature issue view screen, we are aggregating the fix-version of epics which has this feature set and displaying them through a script field called 'Feature Fix-versions' . As it is a script field, we can not able to search for feature issue with history. Something like, 'Feature Fix-versions was 20.19'.
So, I am trying to write a script JQL function which will go back to epics which are linked with feature and search for history of it's fix-version. As a result, i will get list of epics which had given fix-version. I will be iterating through a results and get the value of feature field for each epic issues. Finally, I will form a JQL from the collected feature values. Ex: 'Feature in (Feature_Issue-1, Feature_Issue-2, Feature_Issue-3).
I have the logic. But, I don't know where to insert this code. FYI, I am referring JQL Alias Example code in https://scriptrunner.adaptavist.com/latest/jira/custom-jql-functions.html
Please help me.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try something like this "Feature " ~ "Feature_Issue-1 Feature_Issue-2 Feature_Issue-3" . Let me know if this worked.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
i fixed this issue => change rtc code field from text -> numberic.
textfield -> not supported
Numberic -> worked
Thanks men!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have fixed it. But, I am getting an new error now.
It throws a Compilation Error.
Here is the error snippet,
2019-02-25 08:58:26,483 http-nio-8080-exec-13 ERROR nnallusamy 538x1771042x2 8mu39i 172.28.122.240 /rest/issueNav/1/issueTable [c.o.j.groovy.jql.ScriptedJqlFunction] Script error for function: workTimeFrameWas.
com.atlassian.jira.jql.parser.JqlParseException: com.atlassian.jira.jql.parser.antlr.RuntimeRecognitionException: MismatchedSetException(92!=null)
at com.atlassian.jira.jql.parser.DefaultJqlQueryParser.parseClause(DefaultJqlQueryParser.java:110)
at com.atlassian.jira.jql.parser.DefaultJqlQueryParser.parseQuery(DefaultJqlQueryParser.java:33)
at com.atlassian.jira.jql.parser.JqlQueryParser$parseQuery.call(Unknown Source)
at com.onresolve.jira.groovy.jql.WorkTimeFrameWas.mergeQuery(workTimeFreameWas.groovy:124)
at com.onresolve.jira.groovy.jql.WorkTimeFrameWas.validate(workTimeFreameWas.groovy:62)
at com.onresolve.jira.groovy.jql.JqlFunction$validate$14.call(Unknown Source)
at com.onresolve.jira.groovy.jql.JqlFunction$validate$14.call(Unknown Source)
at com.onresolve.jira.groovy.jql.ScriptedJqlFunction.validate(ScriptedJqlFunction.groovy:113)
Caused by: com.atlassian.jira.jql.parser.antlr.RuntimeRecognitionException: MismatchedSetException(92!=null)
at com.atlassian.jira.jql.parser.antlr.LexerErrorHelper.handleError(LexerErrorHelper.java:48)
at com.atlassian.jira.jql.parser.antlr.JqlLexer.recover(JqlLexer.java:130)
at com.atlassian.jira.jql.parser.antlr.JqlLexer.recover(JqlLexer.java:136)
at com.atlassian.jira.jql.parser.antlr.JqlLexer.mERRORCHAR(JqlLexer.java:1953)
at com.atlassian.jira.jql.parser.antlr.JqlLexer.mTokens(JqlLexer.java:2691)
at org.antlr.runtime.BufferedTokenStream.fetch(BufferedTokenStream.java:143)
at org.antlr.runtime.BufferedTokenStream.sync(BufferedTokenStream.java:137)
at org.antlr.runtime.CommonTokenStream.skipOffTokenChannels(CommonTokenStream.java:116)
at org.antlr.runtime.CommonTokenStream.LT(CommonTokenStream.java:102)
at org.antlr.runtime.BufferedTokenStream.LA(BufferedTokenStream.java:174)
at com.atlassian.jira.jql.parser.antlr.JqlParser.operator(JqlParser.java:1118)
at com.atlassian.jira.jql.parser.antlr.JqlParser.terminalClause(JqlParser.java:645)
at com.atlassian.jira.jql.parser.antlr.JqlParser.notClause(JqlParser.java:555)
at com.atlassian.jira.jql.parser.antlr.JqlParser.andClause(JqlParser.java:451)
at com.atlassian.jira.jql.parser.antlr.JqlParser.orClause(JqlParser.java:366)
at com.atlassian.jira.jql.parser.antlr.JqlParser.clause(JqlParser.java:328)
at com.atlassian.jira.jql.parser.antlr.JqlParser.query(JqlParser.java:237)
at com.atlassian.jira.jql.parser.DefaultJqlQueryParser.parseClause(DefaultJqlQueryParser.java:103)
... 7 more
Caused by: MismatchedSetException(92!=null)
at com.atlassian.jira.jql.parser.antlr.JqlLexer.recover(JqlLexer.java:135)
... 23 more
Here is my code:
package com.onresolve.jira.groovy.jql
import com.atlassian.jira.bc.issue.search.SearchService;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.jql.parser.JqlQueryParser;
import com.atlassian.jira.jql.query.LuceneQueryBuilder;
import com.atlassian.jira.jql.query.QueryCreationContext;
import com.atlassian.jira.jql.validator.NumberOfArgumentsValidator;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.util.MessageSet;
import com.atlassian.query.clause.TerminalClause;
import com.atlassian.query.operand.FunctionOperand;
import groovy.util.logging.Log4j;
import org.apache.lucene.search.Query;
//My custom scripts - Starts
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.project.Project;
import com.atlassian.jira.bc.project.ProjectService;
import com.atlassian.jira.jql.parser.JqlQueryParser;
import com.atlassian.jira.issue.search.SearchProvider;
import com.atlassian.jira.issue.search.SearchResults;
import com.atlassian.jira.web.bean.PagerFilter;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
//My custom scripts - Ends
import java.text.MessageFormat;
@Log4j
class WorkTimeFrameWas extends AbstractScriptedJqlFunction implements JqlQueryFunction {
/**
* Modify this query as appropriate.
*
* See {@link java.text.MessageFormat} for details
*/
public static final String TEMPLATE_QUERY =
"""issuetype = Epic and "Feature Link" is not EMPTY and fixVersion was {0}""";
def queryParser = ComponentAccessor.getComponent(JqlQueryParser);
def luceneQueryBuilder = ComponentAccessor.getComponent(LuceneQueryBuilder);
def searchService = ComponentAccessor.getComponent(SearchService);
def searchProvider = ComponentAccessor.getComponent(SearchProvider);
def issueManager = ComponentAccessor.getIssueManager();
def applicationUser = ComponentAccessor.getJiraAuthenticationContext().getUser();
@Override
String getDescription() {
"Fetch Feature issues which had/have given fixVersion";
}
@Override
MessageSet validate(ApplicationUser user, FunctionOperand operand, TerminalClause terminalClause) {
def messageSet = new NumberOfArgumentsValidator(1, getI18n()).validate(operand);
if (messageSet.hasAnyErrors()) {
return messageSet;
}
def query = mergeQuery(operand);
messageSet = searchService.validateQuery(user, query);
messageSet;
}
@Override
List<Map> getArguments() {
[
[
description: "Version to fetch feature issues",
optional: false,
]
]
}
@Override
String getFunctionName() {
"workTimeFrameWas"
}
@Override
Query getQuery(QueryCreationContext queryCreationContext, FunctionOperand operand, TerminalClause terminalClause) {
log.debug("Hello Nallu");
//Defining Feature Link custom field object
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def featureLink = customFieldManager.getCustomFieldObject("customfield_15727");
def featureLinkList = [];
def firstQuery = MessageFormat.format(TEMPLATE_QUERY, operand.args.first());
def firstquery = queryParser.parseQuery(firstQuery);
def SearchResults = searchProvider.search(firstquery, applicationUser, PagerFilter.getUnlimitedFilter());
// Return the issues from the JQL Query
SearchResults.getIssues().each { documentIssue ->
featureLinkList.add(documentIssue.getCustomFieldValue(featureLink).toString());
}
log.debug("${featureLinkList}");
if(featureLinkList)
{
def queryTemp = featureLinkList.unique().join(',').toString();
def secondQuery = "key in (" + queryTemp + ")";
def query = queryParser.parseQuery(secondQuery);
luceneQueryBuilder.createLuceneQuery(queryCreationContext, query.whereClause);
}
else
{
def secondQuery = firstQuery;
def query = queryParser.parseQuery(secondQuery);
luceneQueryBuilder.createLuceneQuery(queryCreationContext, query.whereClause);
}
}
private com.atlassian.query.Query mergeQuery(FunctionOperand operand) {
def queryStr = MessageFormat.format(TEMPLATE_QUERY, operand.args.first());
queryParser.parseQuery(queryStr);
}
}
This work fine when i pass argument as 18.11. But, If i send an argument with wildcard character (ex: "*18.11*") it throws an error saying 'Scripted function "workTimeFrameWas" compilation failure. Contact administrator and check logs. Message: com.atlassian.jira.jql.parser.antlr.RuntimeRecognitionException: MismatchedSetException(42!=null)'
I have manually tried with wildcard character and it works fine. JQL: issuetype = Epic AND "Feature Link" is not EMPTY AND fixVersion was "*18.11*"
@Sid can you please tell me what i am doing wrong here.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @nallu , try fixVersion ~ "*18.11*" instead of fix version "was"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Sid ,
Actually, I could not use like ~ operator. As per my requirement, I need to get list of issues which had (past) given fix version. Using like ~ operator will return only the issues which has (present) given fix version currently.
So, I want to use `was' operator.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @nallu
Now it is more clear to me, fixVersion was in versionMatch(".*18.11*.") . this might get you results. Let me know if that works
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.