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

> 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

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.

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)

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?

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?

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)

Try using the project key, not name.

> 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.

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)

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.

Any suggestions guys?

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()

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published yesterday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

71 views 0 5
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