I'm trying to write a JQL function that finds all issues with disabled custom field options. How can I access this custom field data? I don't want to hardcode a list of disabled options. I'm using JIRA version 5.1.5.
Community moderators have prevented the ability to post new answers.
Sorry I thought you were trying to write a query. Here is the code that will get issues with options that have been disabled.
It accepts two parameters. First one being theproject key and the second being the custom field name. If you need the whole plugin I can upload it to bitbucket tonight. Let me know.
package com.stygian.jira.plugugins.jql; import com.atlassian.crowd.embedded.api.User; import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.issue.Issue; import com.atlassian.jira.issue.customfields.option.Option; import com.atlassian.jira.issue.fields.CustomField; import com.atlassian.jira.project.Project; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.atlassian.jira.JiraDataType; import com.atlassian.jira.JiraDataTypes; import com.atlassian.jira.jql.operand.QueryLiteral; import com.atlassian.jira.jql.query.QueryCreationContext; import com.atlassian.jira.plugin.jql.function.AbstractJqlFunction; import com.atlassian.jira.util.MessageSet; import com.atlassian.jira.util.NotNull; import com.atlassian.query.clause.TerminalClause; import com.atlassian.query.operand.FunctionOperand; import com.google.common.collect.Iterables; import java.util.Collection; import java.util.Collections; import java.util.LinkedList; import java.util.List; /** * Echoes the the string passed in as an argument. */ public class DisabledOptionSearchFunction extends AbstractJqlFunction { private static final Logger log = LoggerFactory.getLogger(DisabledOptionSearchFunction.class); public MessageSet validate(User searcher, FunctionOperand operand, TerminalClause terminalClause) { return validateNumberOfArgs(operand, 2); } public List<QueryLiteral> getValues(QueryCreationContext queryCreationContext, FunctionOperand operand, TerminalClause terminalClause) { final List<QueryLiteral> literals = new LinkedList<QueryLiteral>(); Project project = ComponentAccessor.getProjectManager().getProjectObjByKey(operand.getArgs().get(0)); try { Collection<Long> issueIds = ComponentAccessor.getIssueManager().getIssueIdsForProject(project.getId()); for(Long issueId:issueIds) { Issue issue = ComponentAccessor.getIssueManager().getIssueObject(issueId); CustomField customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName(operand.getArgs().get(1)); Collection<Option> options = (Collection)issue.getCustomFieldValue(customField); if(options != null) { for(Option option:options) { if(option.getDisabled() == true) { literals.add(new QueryLiteral(operand, issueId)); } } } } } catch(Exception exc) { log.error(exc.toString()); } return literals; } public int getMinimumNumberOfExpectedArguments() { return 2; } public JiraDataType getDataType() { return JiraDataTypes.ISSUE; } }
Cheers
Bhushan
Oh, wow. Thanks! That should solve my problem. I'll let you know if I have any issues making it work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Vanessa,
Did it help?
Cheers
Bhushan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I should know tomorrow. Sidetracked with other stuff today. I'll let you know.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Vanessa,
Not sure how you managed to disable an option in the custom field but the answer for your question about JQL is No.
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.
Yes I am saying it is not possible with current JQL search to write a query to get issues based on if a selected option is a select list is "DISABLED". Refer to the advanced search guide at
https://confluence.atlassian.com/display/JIRA/Advanced+Searching
Also, would you please let me know how you disabled an option in the selected list?
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What is a disabled custom field option?
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.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.