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

Disabled custom field options

Vanessa Strazdas June 4, 2013

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.

4 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Bhushan Nagaraj
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.
June 4, 2013

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

Vanessa Strazdas June 4, 2013

Oh, wow. Thanks! That should solve my problem. I'll let you know if I have any issues making it work.

Bhushan Nagaraj
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.
June 4, 2013

Hey Vanessa,

Did it help?

Cheers

Bhushan

Vanessa Strazdas June 5, 2013

I should know tomorrow. Sidetracked with other stuff today. I'll let you know.

0 votes
Bhushan Nagaraj
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.
June 4, 2013

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.

Vanessa Strazdas June 4, 2013
The answer to what is No? Are you saying it's impossible to create a JQL function that can check if a selected option in a select list has been disabled? I find that hard to believe.
Bhushan Nagaraj
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.
June 4, 2013

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?

Vanessa Strazdas June 4, 2013
You click configure then to the right of the option you want to disable, you click disable. Yes, I realize I can't just do a regular query. I clearly need to write some code. I'm trying to figure out how to write that code.
0 votes
Vanessa Strazdas June 4, 2013
In a select list, options can be disabled. That way they remain for searching but are no longer selectable. I should have clarified that I meant options in a select list.
0 votes
Timothy
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.
June 4, 2013

What is a disabled custom field option?

Vanessa Strazdas June 4, 2013
In a select list, options can be disabled. That way they remain for searching but are no longer selectable. I should have clarified that I meant options in a select list.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events