bobcarroll / jira-client

A simple JIRA REST client for Java
Other
476 stars 380 forks source link

Select List (single choice) Custom Field #214

Open raymondyam opened 7 years ago

raymondyam commented 7 years ago

In the Quick Start Example, an example is given for a text field custom field:

        /* Pretend customfield_1234 is a text field. Get the raw field value... */
        Object cfvalue = issue.getField("customfield_1234");

        /* ... Convert it to a string and then print the value. */
        String cfstring = Field.getString(cfvalue);
        System.out.println(cfstring);

        /* And finally, change the value. */
        issue.update()
            .field("customfield_1234", "new value!")
            .execute();

When I tried it on a Select List (single choice) custom field, it does not work. Neither does the multi-select box approach in the example work. As a result, does anyone know of a way to read and update a Select List (single choice) custom field? Thanks!

pa-ling commented 6 years ago

I could not make that work with version 0.5 from maven, but using the sources from the master branch it is possible in the following way: read:

CustomFieldOption singleSelect = Field.getResource(
    CustomFieldOption.class,
    issue.getField("<your custom field>"),
    jira.getRestClient()
);
System.out.println(singleSelect.getValue());

write:

issue.update().field("<your custom field>", new Field.ValueTuple("value", "<your value>"));

I hope I could help you!

nilrieraDxc commented 4 years ago

I could not make that work with version 0.5 from maven, but using the sources from the master branch it is possible in the following way: read:

CustomFieldOption singleSelect = Field.getResource(
    CustomFieldOption.class,
    issue.getField("<your custom field>"),
    jira.getRestClient()
);
System.out.println(singleSelect.getValue());

write:

issue.update().field("<your custom field>", new Field.ValueTuple("value", "<your value>"));

I hope I could help you!

Hi, thanks for your help, i have to be able to put a null value there, is it possible? is there a way to put a null value? it's a little frustrating