Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking CheckBox on customfield #71

Closed
andrew-boutin opened this issue Mar 10, 2015 · 15 comments
Closed

Checking CheckBox on customfield #71

andrew-boutin opened this issue Mar 10, 2015 · 15 comments

Comments

@andrew-boutin
Copy link

Hi, first of all thanks for creating this awesome tool!

In Jira I have a custom field that is of type Checkboxes with id = customfield_10023. The only option is "Yes" which has an id of 10013. I thought that doing what you did in the README.md file, for multi-select boxes, would work, but I can't seem to get it to. Is it not supported or is there a different way to set check boxes? Thank you very much.

// Tried using the id
symptom.update().field("customfield_10023", new ArrayList() {{
                   add(Field.valueById("10013"));
              }})
              .execute();

// Also tried using the value
symptom.update().field("customfield_10023", new ArrayList() {{
                   add("Yes");
              }})
              .execute();

Both ways I get the following error:

Error during Jira Symptom creation: net.rcarz.jiraclient.JiraException: Failed to update issue TEST-1056
net.rcarz.jiraclient.JiraException: Failed to update issue TEST-1056
    at net.rcarz.jiraclient.Issue$FluentUpdate.execute(Issue.java:191)
    at devopsdatamigrator.JiraHandle.createSymptom(JiraHandle.java:150)
    at devopsdatamigrator.DataMigrator.migrateIssues(DataMigrator.java:208)
    at devopsdatamigrator.DataMigrator.migrateObjects(DataMigrator.java:70)
    at devopsdatamigrator.DataMigrator.main(DataMigrator.java:252)
Caused by: net.rcarz.jiraclient.RestException: 400 Bad Request: {"errorMessages":[],"errors":{"Customer Data Unavailable Flag":"expected Object"}}
    at net.rcarz.jiraclient.RestClient.request(RestClient.java:160)
    at net.rcarz.jiraclient.RestClient.request(RestClient.java:182)
    at net.rcarz.jiraclient.RestClient.request(RestClient.java:200)
    at net.rcarz.jiraclient.RestClient.put(RestClient.java:380)
    at net.rcarz.jiraclient.RestClient.put(RestClient.java:398)
    at net.rcarz.jiraclient.Issue$FluentUpdate.execute(Issue.java:189)
@bobcarroll
Copy link
Owner

Interesting. This might be similar to another issue someone e-mailed me about. Do you happen to know what the JSON is expected to look like? I haven't come across that field type before.

@andrew-boutin
Copy link
Author

Does this help you at all?

"customfield_10023":[{"value":"Yes","id":"10013"}]

I got this by viewing the issue's fields in a debugger after retrieving an issue from Jira - I manually set the checkbox using the Jira web interface so that's what it should "look like" when a checkbox is checked.

Thanks for the fast response on this!

EDIT:
I don't know if this helps, but this is the format from a text field custom field.

"customfield_10011":{"value":"Customer","id":"10001"}

@bobcarroll
Copy link
Owner

Yes that does help. I'll take a look soon.

@chaplinkyle
Copy link
Contributor

What I have found so far:

I set up the same type of custom field in jira-client.atlassian.net. When you login check out https://jira-client.atlassian.net/rest/api/2/issue/JIR-1/editmeta.

Field in question metadata: "customfield_10027":{"required":false,"schema":{"type":"array","items":"string","custom":"com.atlassian.jira.plugin.system.customfieldtypes:multicheckboxes","customId":10027}

Schema defines array of type string and that is what we're passing. I checked.

@andrew-boutin
Copy link
Author

@chaplinkyle Did you attempt to set one of the checkboxes in the multicheckbox using jira-client? Thanks for taking the time to look into this!

@andrew-boutin
Copy link
Author

I'm not sure if the meta data I retrieved for my custom field helps in this issue or not:

customfield_10025 {"required":false,"schema": "type":"array","items":"string","custom":"com.atlassian.jira.plugin.system.customfieldtypes:multicheckboxes","customId":10025},"name":"Customer Data Loss Flag","hasDefaultValue":false,"operations":["add","set","remove"],"allowedValues":[{"self":" ...server url... /jira/rest/api/2/customFieldOption/10014","value":"Yes","id":"10014"}]}

@andrew-boutin
Copy link
Author

I have managed to set checkboxes, here is how:

Issue symptom = jiraClient.getIssue("EM-559");

JSONObject valueObject = new JSONObject(); // from import net.sf.json.JSONObject;
valueObject.put("value", "Yes"); // Yes it the only option for this particular checkbox field
ArrayList<Object> fields = new ArrayList<Object>();
fields.add(valueObject);

symptom.update().field("customfield_10023", fields).execute();

I'm not sure if it was designed to only work this way or if there is another way. If not then I hope what I have found helps you fix the implementation. At the least maybe now some comments can be made about how to set checkboxes with jira-client. Thanks again for the awesome tool.

@bobcarroll
Copy link
Owner

That helped a lot actually. The problem is the metadata returned by JIRA lies about what the type actually is. An array of strings (as the metadata indicates) should be an array of strings, but it's really expecting an array of dictionaries.

Can you build jira-client from master and try this:

Issue symptom = jiraClient.getIssue("EM-559");
symptom.update().field("customfield_10023", new ArrayList<Object>() {{ add("Yes") }}).execute();

@stevegore
Copy link
Contributor

Hi
I'm having this issue for all multi-select fields. I've tried your suggestion above to no avail. Any other suggestions? I've noticed there's an open feature request for this as well. #93

@andrew-boutin
Copy link
Author

I just confirmed that this worked for me. I created a custom field of type "Select List (multiple choices)" called "multiSelectTest" with custom field id "10101". The available options were "one", "two", and "three".

Issue problem = jiraClient.getIssue("EM-8648");

JSONObject oneObject = new JSONObject(); // from import net.sf.json.JSONObject;
oneObject.put("value", "one");
JSONObject twoObject = new JSONObject();
twoObject.put("value", "two");

ArrayList<Object> fields = new ArrayList<Object>();
fields.add(oneObject);
fields.add(twoObject);

problem.update().field("customfield_10101", fields).execute();

The String representation of 'fields' is "[{"value":"one"}, {"value":"two"}]".

Hope this helps!

@stevegore
Copy link
Contributor

Thanks for this. I actually resolved the issue by making a change to the client. I'll try and create a pull request tomorrow.

@andrew-boutin
Copy link
Author

I'm interested in knowing what wasn't working correctly with the client, I thought it was working correctly.

@stevegore
Copy link
Contributor

Thanks for this. I actually resolved the issue by making a change to the client. I'll try and create a pull request tomorrow.
On 24 Jul 2015 12:29 am, Andrew Boutin notifications@github.com wrote:I just confirmed that this worked for me. I created a custom field of type "Select List (multiple choices)" called "multiSelectTest" with custom field id "10101". The available options were "one", "two", and "three".

Issue problem = jiraClient.getIssue("EM-8648");

JSONObject oneObject = new JSONObject(); // from import net.sf.json.JSONObject;
oneObject.put("value", "one");
JSONObject twoObject = new JSONObject();
twoObject.put("value", "two");

ArrayList fields = new ArrayList();
fields.add(oneObject);
fields.add(twoObject);

problem.update().field("customfield_10101", fields).execute();

The String representation of 'fields' is "[{"value":"one"}, {"value":"two"}]".

Hope this helps!

—Reply to this email directly or view it on GitHub.

@stevenlordiam
Copy link

Can you update this merged code in Maven repo? Need this API so much. Thanks. @rcarz

BTW the define JSON method is not working for me. I used code from Maven 0.5 version. Returns:
Field 'customfield_10101' does not exist or read-only.

@vzenzo
Copy link

vzenzo commented Sep 8, 2020

Can somebody help with this? None of the options up there work for me, I constantly get

400 400: {"errorMessages":[],"errors":{"Detected on Env":"expected Object","Country":"expected Object"}}

I've added them as objects

    JSONObject envObject = new JSONObject();
    envObject.put("value", "UAT");
    envObject.put("id","10911");

    JSONObject countryObject = new JSONObject();
    countryObject.put("value", "RO");
    countryObject.put("id", "10900");

newIssue.field("customfield_11500", new ArrayList() {{add(countryObject);}})
.field("customfield_11503", new ArrayList() {{add(envObject);}})
.execute();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants