Hello team
My code bellow work perfectly in script field , but when i move it to a profields post function an error appear . I need help please.
Error = startup failed: Script1.groovy: 13: unable to resolve class com.atlassian.jira.jql.parser.JqlQueryParser @ line 13, column 1. import com.atlassian.jira.jql.parser.JqlQueryParser ^
My code :
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.Project
import com.deiser.jira.profields.api.field.FieldService
import com.deiser.jira.profields.api.field.item.status.StatusItemService
import com.deiser.jira.profields.api.field.status.StatusField
import com.deiser.jira.profields.api.value.ValueService
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.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.issue.Issue
def sdUser = ComponentAccessor.getJiraAuthenticationContext().getUser() // we can use it if we don't know the name of the user
log.warn("the user key is " + sdUser)
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def query1 = jqlQueryParser.parseQuery("project = KP")
def query2 = jqlQueryParser.parseQuery("project = KP and status =\"Done\" ")
def results1 = searchProvider.search(query1, sdUser, PagerFilter.getUnlimitedFilter())
def results2 = searchProvider.search(query2, sdUser, PagerFilter.getUnlimitedFilter())
def valueService = ComponentAccessor.getOSGiComponentInstanceOfType(ValueService.class)
def fieldService = ComponentAccessor.getOSGiComponentInstanceOfType(FieldService.class)
def statusItemService = ComponentAccessor.getOSGiComponentInstanceOfType(StatusItemService.class)
Project project = issue.projectObject
def statusField = (StatusField) fieldService.get(9)
def newStatusItem = statusItemService.getItemByText((StatusField) statusField, "CLÔTURÉ")
valueService.setValue(project, (StatusField) statusField, newStatusItem)
The class JqlQueryParser is not accesible from Profields. We are working to include it in the app.
You can do the same with the following script. I discard the end of the script where you are setting the status item. As you can see, you should use the status id instead of the text to search by it. You can find this id in the status administration inside de text link of the "Edit" link.
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.jql.builder.JqlQueryBuilder
import com.atlassian.jira.web.bean.PagerFilter
def searchService = ComponentAccessor.getOSGiComponentInstanceOfType(SearchService.class)
// we can use it if we don't know the name of the user
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
def jqlQueryBuilder = JqlQueryBuilder.newBuilder()
def clause = jqlQueryBuilder.newClauseBuilder()
.project("KP")
.and()
.status("10000") // You should use the status id
.buildClause()
def query = jqlQueryBuilder.where().addClause(clause).buildQuery()
def issues = searchService.search(loggedInUser, query, PagerFilter.unlimitedFilter).issues
I changed my code without the JQL . But there are a problem , the last line doesn't work , the rest it's okay , and it seems weird. Please Help .
My code is below:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.Project
import com.deiser.jira.profields.api.field.number.NumberField
import com.deiser.jira.profields.api.field.FieldService
import com.deiser.jira.profields.api.field.item.status.StatusItemService
import com.deiser.jira.profields.api.field.status.StatusField
import com.deiser.jira.profields.api.value.ValueService
import com.atlassian.jira.issue.Issue
def valueService = ComponentAccessor.getOSGiComponentInstanceOfType(ValueService.class)
def fieldService = ComponentAccessor.getOSGiComponentInstanceOfType(FieldService.class)
def statusItemService = ComponentAccessor.getOSGiComponentInstanceOfType(StatusItemService.class) //for the status item
Project project = issue.projectObject
// get value of done and created issue
def donefield = (NumberField)fieldService.get(41)// ID of field number done
def createdfield = (NumberField)fieldService.get(42)// ID of field number created
def numbervaluecreated = valueService.getValue(issue.projectObject,(NumberField) createdfield)
def numbervaluedone = valueService.getValue(issue.projectObject,(NumberField) donefield)
// set value of done field
valueService.setValue(project,(NumberField)donefield,numbervaluedone+ 1.0)
log.warn("the value of created issues after updating is" + numbervaluedone + 1.0)
def statusField = (StatusField) fieldService.get(9)
// Gets the status item base on a text
def newStatusItem = statusItemService.getItemByText((StatusField) statusField, "CLÔTURÉ")
// Set the value in the "other" project
//(this line doesn't work)
valueService.setValue(project, (StatusField) statusField, newStatusItem)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you add these next lines before the line that is not working and send the related errors of the atlassian-jira.log at the moment of the execution?
log.warn("Project: ${project}")
log.warn("Field: ${statusField}")
log.warn("New item: ${newStatusItem}")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The class JqlQueryParser is not accesible from Profields. We are working to include it in the app.
You can do the same with the following script. I discard the end of the script where you are setting the status item. As you can see, you should use the status id instead of the text to search by it. You can find this is in the status administration inside de text link of the "Edit" link.
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.jql.builder.JqlQueryBuilder
import com.atlassian.jira.web.bean.PagerFilter
def searchService = ComponentAccessor.getOSGiComponentInstanceOfType(SearchService.class)
// we can use it if we don't know the name of the user
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
def jqlQueryBuilder = JqlQueryBuilder.newBuilder()
def clause = jqlQueryBuilder.newClauseBuilder()
.project("KP")
.and()
.status("10000") // You should use the status id
.buildClause()
def query = jqlQueryBuilder.where().addClause(clause).buildQuery()
def issues = searchService.search(loggedInUser, query, PagerFilter.unlimitedFilter).issues
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @carlos_fernandez ,
Any timeline on when the JQLQueryParser will be accessible in ProFields?
I´m currently trying to run a rather complicated query using Altavista´s ScriptRunner "issueFunction in linkedIssuesOf("xxx")", and I´m not familiar with how to build those queries that include custom fields using the JQLQueryBuilder.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In order to give you a better support, please contact us through our support portal:
https://jira.deiser.com/plugins/servlet/desk/portal/1
Sorry for not getting back to you sooner, but being an open site, we may miss some questions like this.
Hope it helps you!
Leo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.