Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Unable to parse Jql Query , Throwing Jql Exception Edited

Hi i am trying to add a script in a validator, but every time i am trying to exeute i am getting this error.,Even i tried this JQL query in Issue Search its working , but here its not able to print that.

 

Error : --

 

com.atlassian.jira.jql.parser.JqlParseException: com.atlassian.jira.jql.parser.antlr.RuntimeRecognitionException: MismatchedSetException(123!=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 Script570.run(Script570.groovy:34)  

 

 

 

My Code is  : - 

 

import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.component.ComponentAccessor ;
import com.atlassian.jira.issue.MutableIssue ;
import com.atlassian.jira.issue.fields.config.FieldConfig ;
import com.atlassian.jira.issue.customfields.option.Options ;
import com.atlassian.jira.issue.CustomFieldManager ;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.fields.IssueLinksSystemField;
import com.atlassian.jira.issue.search.SearchProvider;
import com.atlassian.jira.jql.parser.JqlQueryParser;
import com.atlassian.jira.web.bean.PagerFilter;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.user.util.UserManager;
import org.apache.log4j.Logger

 

log.setLevel(org.apache.log4j.Level.DEBUG)
log.debug("test")
String jqlFilter = ""
String brJqlFilter = ""
boolean pass = true
log.debug("testing jqlFilter" + jqlFilter )
//def issueManager = ComponentAccessor.getIssueManager();
UserManager userManager = ComponentAccessor.getComponent(UserManager)
ApplicationUser user = userManager.getUserByName("INT_JIRA")

def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
jqlFilter = jqlQueryParser.parseQuery("'Parent Link' = " + issue.key +" AND issuetype = BR")
def query = jqlQueryParser.parseQuery(jqlFilter)
def results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter())
log.debug(" Printing Results >>>>>>>>>>>>" + results )
//Looping throhg my BR issues in my Planview parent issue
if(results.getTotal()>0){

Integer i = 0;
results.getIssues().each { br ->

//Conditions before we check FR
if(br.status.name != "Completed"){
pass = false
log.debug(" printing BR Status >>>>>>>>>>>>" + br.status.name )
} else{
brJqlFilter = jqlQueryParser.parseQuery("'Parent Link' ="+ br.key +"AND issuetype = FR")

def brQuery = jqlQueryParser.parseQuery(brJqlFilter)
def brResults = searchProvider.search(brQuery, user, PagerFilter.getUnlimitedFilter())

//Looping through all the fr issues in my BR parent issue
if(brResults.getTotal()>0){

brResults.getIssues().each { fr ->
if(fr.status.name == "Completed"){
log.debug(" printing FR Status >>>>>>>>>>>>" + fr.status.name )
log.debug("Entering Fr If Block")
pass = true
}else{
log.debug("Entering Fr else Block")
//conditions whether pass or no pass
//if FR does not meet conditions we need
pass = false
}

}
}

}
}
} else return false //this means yuou cannot do transition because for somereason no BR

1 answer

0 votes
Leo Community Leader Jan 20, 2020 • edited

Hi @J Manas Kumar

Are you in Jira server or in cloud?

if you are in server, and if I understood correctly you should not close/complete parent task if anyone of it's child(BR) issue is not closed/completed

Also I could see that you are parsing over 2 inner levels for completing top level parent task instead I would suggest you to add the same kind of condition to BR. so that you can't complete BR unless all it's FRs completed. in that case no need to validate FRs again when in it's validated during BR's completion

Hopefully below code should do the trick for you

import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.web.bean.PagerFilter
import org.apache.log4j.Level
import org.apache.log4j.Logger

def appUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def linkManager = ComponentAccessor.getIssueLinkManager()
def searchService = ComponentAccessor.getComponent(SearchService.class)
def issueManager = ComponentAccessor.getIssueManager()
def log = Logger.getLogger("Jira Log")
log.setLevel(Level.DEBUG)

def jqlSearch = "\"Parent Link\" = ${issue.key} AND issuetype = BR"
def pass = true

SearchService.ParseResult parseResult = searchService.parseQuery(appUser, jqlSearch)
if (parseResult.isValid()) {
def searchResult = searchService.search(appUser, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
def issues = searchResult.issues.collect {issueManager.getIssueObject(it.id)}

issues.each { i ->
if (i.getStatus().name != 'Completed'){
pass = false
}
}
if(pass){
return true
}else{
return false
}
} else {
log.error("Invalid JQL: " + jqlSearch)
}

 BR,

Leo

how to stop the flow as the issue workflow is not stopping after if block.

Pleas go through the next comment.

Hi @Leo 

I did modify little bit and now i am able to get FR issues's Status , But i am not able to stop it when its Status != "Completed".Its not throwing any error. directly passing the next state.

Below i have attached the code , pLease have a look into it if you can.

 

import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.web.bean.PagerFilter;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.user.util.UserManager;import org.apache.log4j.Level
import org.apache.log4j.Logger

//def appUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
UserManager userManager = ComponentAccessor.getComponent(UserManager)
ApplicationUser user = userManager.getUserByName("INT_JIRA")
def linkManager = ComponentAccessor.getIssueLinkManager()
def searchService = ComponentAccessor.getComponent(SearchService.class)
def issueManager = ComponentAccessor.getIssueManager()
def log = Logger.getLogger("com.citi.jira.listener.ProcessFieldChanges")
log.setLevel(Level.DEBUG)
log.debug("Testing FR Issue Error")
def jqlSearch = "\"Parent Link\" = ${issue.key} AND issuetype = BR"
def pass = true
log.debug("Getting Result for JQL Query : -----" + jqlSearch)

SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlSearch)
if (parseResult.isValid()) {
def searchResult = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
def issues = searchResult.issues.collect {issueManager.getIssueObject(it.id)}
log.debug("Getting Each Issues : -----" + issues)

issues.each { i ->
if (i.getStatus().name != "Completed"){
pass = false
}else{

log.debug("Entering into BR Else Block : ----->>>>>")
def jqlSearch1 = "\"Parent Link\" = ${i.key} AND issuetype = FR"
log.debug("Getting Result for FR JQL Query : ----->>>>>" + jqlSearch1)
SearchService.ParseResult parseResult1 = searchService.parseQuery(user, jqlSearch1)
def searchResult1 = searchService.search(user, parseResult1.getQuery(), PagerFilter.getUnlimitedFilter())
def issues1 = searchResult1.issues.collect {issueManager.getIssueObject(it.id)}
log.debug("Getting FR Each Issues : ----->>>>>" + issues1)
issues1.each { j ->
if(j.getStatus().name != "Completed"){
log.debug("Getting FR Each Issues if : ----->>>>>" + j.getStatus().name)
pass = false
}else { pass 
}
}
}
/* if (i.getStatus().name != "Completed"){
pass = false
} */
}
/* if(pass){
return true
}else{
return false
}*/
} else return false

/*{
log.error("Invalid JQL: " + jqlSearch)
}*/

Leo Community Leader Jan 21, 2020

Can you briefly explain about how you are trying to validate issue status?

If I understood correctly the hierarchical is Parent Task--> BR --> FR

1. If all BRs completed ---> Parent can move to next step

2. if BRs completed or all FRs of BR(s) completed --> Parent can move to next step

3. if not both it should block the transition, am I right?

Hi @Leo 

 

yes you are absolutely right.

i did it, its working now.i missed at one point out side of the block, now i corrected it.

but one thing i am asking i have done it and its working for 1 issue like 1 Planview --> 1 BR -- > 1 FR -->.

 

suppose 1 plan view has multiple Br and 1 BR ha multiple FR how to do it.

I have pasted the working code below. Please have a look at it, if you can help that would be appreciated.

 

import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.web.bean.PagerFilter;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.user.util.UserManager;

 


import org.apache.log4j.Level
import org.apache.log4j.Logger

//def appUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
UserManager userManager = ComponentAccessor.getComponent(UserManager)
ApplicationUser user = userManager.getUserByName("INT_JIRA")
def linkManager = ComponentAccessor.getIssueLinkManager()
def searchService = ComponentAccessor.getComponent(SearchService.class)
def issueManager = ComponentAccessor.getIssueManager()
def log = Logger.getLogger("com.citi.jira.listener.ProcessFieldChanges")
log.setLevel(Level.DEBUG)
log.debug("Testing FR Issue Error")
def jqlSearch = "\"Parent Link\" = ${issue.key} AND issuetype = BR"
def pass = true
log.debug("Getting Result for JQL Query : -----" + jqlSearch)

SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlSearch)
if (parseResult.isValid()) {
def searchResult = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
def issues = searchResult.issues.collect {issueManager.getIssueObject(it.id)}
log.debug("Getting Each Issues : -----" + issues)

issues.each { br ->
log.debug("Getting BR Status Each BR Issues : ----->>>>>" + br.getStatus().name)
if (br.getStatus().name != "Completed"){
pass = false
}else{

log.debug("Entering into BR Else Block : ----->>>>>")
def jqlSearch1 = "\"Parent Link\" = ${br.key} AND issuetype = FR"
log.debug("Getting Result for FR JQL Query : ----->>>>>" + jqlSearch1)
SearchService.ParseResult parseResult1 = searchService.parseQuery(user, jqlSearch1)
def searchResult1 = searchService.search(user, parseResult1.getQuery(), PagerFilter.getUnlimitedFilter())
def issues1 = searchResult1.issues.collect {issueManager.getIssueObject(it.id)}
log.debug("Getting FR Each Issues : ----->>>>>" + issues1)
issues1.each { fr ->
log.debug("Getting FR Status Each FR Issues : ----->>>>>" + fr.getStatus().name)
if(fr.getStatus().name != "Completed"){
log.debug("Getting FR Each Issues if : ----->>>>>" + fr.getStatus().name)
pass = false
}else { pass = true
log.debug("Getting FR Each Issues else : ----->>>>>" + fr.getStatus().name)
}
}
}
}
return pass
} else return false

/*{
log.error("Invalid JQL: " + jqlSearch)
}*/

 

 

Regards

Manas

Leo Community Leader Jan 21, 2020

you just need to remove pass = true line from else part of FR issue status validation, and that should run for all issues linked, other than all looks good to me

and your code will run like below

1. If any one BR not completed the planview transition is blocked(IF part)

2. even if BR is completed, all FRs should be completed to allow Planview issue transition(ELSE part)

BR,

Leo

Like J Manas Kumar likes this

Hi @Leo 

 

another help i want to get from you if you know it.

i didnt know much about Linked Issues(ex:clones,relates to etc).

my requirement is to create a custom linked issue ex: Designed For from one Issue side and it should link to another issue Field like Designed By.

i have created Designed By and For in linked Issues, but i want those only two while selecting the fields in specific issues, not the whole bunch of other issues like clones to and relates to.

 

i have attached the screen shots for reference.

Here in Designed For 1 screen shot i am getting all issues like relates to , clones to , everything, but i want only Desgined For and Designed By.

Is that possible? to fetch all values of linked issues and show only specific issues or custom issues created by us?

Designed By.PNGDesigned For 1.PNGDesigned For.PNG

Leo Community Leader Jan 21, 2020

I never done that by myself, maybe THIS THREAD  would give you some idea

Thanks @Leo  for your help.

 

 

Regards

Manas

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you