Groovy help

Sanu Soman
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.
April 1, 2014

Hi All,

Could you please help me on following,

1. How to add order by created date parameter (ORDER BY created ASC) to the below JQuery in my groovy script?

Query query=builder.project().eq("DEMO - IT FX QA").and().customField(10284).gtEqFunc("startOfWeek").and().customField(10284).ltEqFunc("endOfWeek")buildQuery()

2. Also, after querying above search getting many issue results, like JIRA-1, JIRA-2, JIRA-3 etc. Could you please suggest how I can assign these result to seperate string value? like STRING1, STRING2 etc

is, STRING1 = JIRA1, STRING2 = JIRA-2 like. Currrently I'm getting the result count by below steps,

Query query=builder.project().eq("DEMO - IT FX QA").and().customField(10284).gtEqFunc("startOfWeek").and().customField(10284).ltEqFunc("endOfWeek")buildQuery()
        SearchResults searchResults = searchProvider.search(query, authenticationContext.getLoggedInUser(), PagerFilter.getUnlimitedFilter());
List<Issue> searchIssues = searchResults.getIssues();
totalIssues = searchIssues.size();

Please help.

Many thanks.

3 answers

1 vote
JamieA
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.
April 2, 2014

> How to add order by created date parameter (ORDER BY created ASC) to the below JQuery in my groovy script?

builder.where().project("JRA").endWhere().orderBy().createdDate(SortOrder.ASC).buildQuery()

> Also, after querying above search getting many issue results, like JIRA-1, JIRA-2, JIRA-3 etc. Could you please suggest how I can assign these result to seperate string value? like STRING1, STRING2 etc

I don't understand what you're asking here.

To get all the keys you can do: searchIssues*.key

Sanu Soman
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.
April 2, 2014

2. From the above query I'm getting many issue number as result (like, JIRA-1, JIRA-2, JIRA-3 etc), so just want to store these to seperate variables (like VAR1 = JIRA-1, VAR2=JIRA-2, VAR3=JIRA-3 etc). Currently by below script I'm storing search result total count to a variable "totalissues",

Query query=builder.project().eq("DEMO - IT FX QA").and().customField(10284).gtEqFunc("startOfWeek").and().customField(10284).ltEqFunc("endOfWeek")buildQuery()
        SearchResults searchResults = searchProvider.search(query, authenticationContext.getLoggedInUser(), PagerFilter.getUnlimitedFilter());
List<Issue> searchIssues = searchResults.getIssues();
totalIssues = searchIssues.size();


Please let me know how it can be possbile.

Hope the query is clear now.

Sanu Soman
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.
April 2, 2014

Caused by: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.jql.builder.DefaultJqlClauseBuilder.where() is applicable for argument types: () values: []
Possible solutions: every(), every(groovy.lang.Closure), endWhere(), voter(), grep(), grep(java.lang.Object)

Sanu Soman
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.
April 2, 2014

Thanks for the response. :)

1. My actual query is,

Query query=builder.project().eq("DEMO - IT FX QA").and().customField(cf1.getIdAsLong()).eq(cf1Value.getValue()).and().customField(cf2.getIdAsLong()).eq(cf2Value.getValue()).and().customField(cf3.getIdAsLong()).eq(cf3Value.getValue()).and().customField(10284).gtEqFunc("startOfWeek").and().customField(10284).ltEqFunc("endOfWeek").buildQuery()

It's working fine and want to sort by created date the search result so just modified the query by,

Query query=builder.where().project().eq("DEMO - IT FX QA").and().customField(cf1.getIdAsLong()).eq(cf1Value.getValue()).and().customField(cf2.getIdAsLong()).eq(cf2Value.getValue()).and().customField(cf3.getIdAsLong()).eq(cf3Value.getValue()).and().customField(10284).gtEqFunc("startOfWeek").and().customField(10284).ltEqFunc("endOfWeek").endWhere().orderBy().createdDate(SortOrder.ASC).buildQuery()

but getting below error.. Could you please suggest what causing this error?

JamieA
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.
April 2, 2014

You just need to break it down into chunks and see where it fails.

> Hope the query is clear now

It's not remotely clear. Are you saying you want to dynamically create a variable for every issue? Why? Or are you saying you want to put the results in a Map where the keys are the issue keys?

Sanu Soman
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.
April 2, 2014

Used simple query to figure out the issue,

Query query=builder.project("DEMO - IT FX QA").buildQuery()

It's working, then tried with,

Query query=builder.project("DEMO - IT FX QA").orderBy().createdDate(SortOrder.ASC).buildQuery()

but getting below error,

Caused by: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.jql.builder.DefaultJqlClauseBuilder.orderBy() is applicable for argument types: () values: []
Possible solutions: every(), every(groovy.lang.Closure), or(), priority(), voter(), grep()

also, tried with,

Query query=builder.where().project("DEMO - IT FX QA").endWhere().orderBy().createdDate(SortOrder.ASC).buildQuery()

but almost same error,

Caused by: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.jql.builder.DefaultJqlClauseBuilder.where() is applicable for argument types: () values: []
Possible solutions: every(), every(groovy.lang.Closure), endWhere(), voter(), grep(), grep(java.lang.Object)

JamieA
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.
April 2, 2014

Try using the project key, not name.

Sanu Soman
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.
April 2, 2014

> It's not remotely clear. Are you saying you want to dynamically create a variable for every issue? Why? Or are you saying you want to put the results in a Map where the keys are the issue keys?

Yes.. want to create variables dynamically based on the search result count and need to store these issue key to the new variables in created date order.

Sanu Soman
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.
April 2, 2014

Project key also not working for me.

Query query=builder.where().project("ITFXQA").endWhere().orderBy().createdDate(SortOrder.ASC).buildQuery()

Error,

Caused by: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.jql.builder.DefaultJqlClauseBuilder.where() is applicable for argument types: () values: []
Possible solutions: every(), every(groovy.lang.Closure), endWhere(), voter(), grep(), grep(java.lang.Object)

Sanu Soman
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.
April 2, 2014

Below query praser method is working,

def jqlQueryParser = ComponentManager.getComponentInstanceOfType(JqlQueryParser.class) as JqlQueryParser
def query = jqlQueryParser.parseQuery("project = "DEMO - IT FX QA" ORDER BY project ASC")

Could you please let me know how I can add ".and().customField(cf1.getIdAsLong()).eq(cf1Value.getValue())" parameter to the quey praser?

This is nothing but checking a custom field value of the current issue in the query.

0 votes
Sanu Soman
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.
April 1, 2014

Tried with orderBy().createdDate(SortOrder.ASC).buildQuery() but getting below error,

Caused by: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.jql.builder.DefaultJqlClauseBuilder.orderBy() is applicable for argument types: () values: []
Possible solutions: every(), every(groovy.lang.Closure), or(), priority(), voter(), grep()

0 votes
Sanu Soman
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.
April 1, 2014

Any suggestions guys?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events