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

How can I set custom field value in Jira Java Rest Client?

Pedro Perez May 1, 2014

Hello,

I can't for the life of me figure out how to set a custom field value when creating an issue.

List<ComplexIssueInputFieldValue> fieldList = new ArrayList<ComplexIssueInputFieldValue>();

Map<String, Object> mapValues = new HashMap<String, Object>();

mapValues.put("value", "suite.robot");

ComplexIssueInputFieldValue fieldValue = new ComplexIssueInputFieldValue(mapValues);

fieldList.add(fieldValue);

issueInputBuilder.setFieldValue("customfield_10200", fieldList);

But that keeps throwing this error:

Caused by: RestClientException{statusCode=Optional.of(400), errorCollections=[ErrorCollection{status=400, errors={customfield_10200=string expected at index 0}, errorMessages=[]}]}

I've seen a lot of other links about the multiple, multiple ways people have done this in the past, but I can't tell if the code has been versioned since then. I'm using 2.0.0-m19.

Thanks!

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Pedro Perez May 14, 2014

After googling around and looking at forums and even talking to Jira support, the solution is simple...don't use the Jira REST client :) ... it's not maintained, the documentation is horribly out of date, and the best answer I could get was that it "wasn't officially supported, please read the API documentation".

Makes you wonder why Jira says it's the "easiest place to get started" ... I guess it is for super basic tasks, but if you need to do anything complex, you're better off writing your own little REST client. Short answer: Don't use the Jira REST client.

3 votes
Aleksander Mierzwicki
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 14, 2014

Another good answer is: it depends on custom field. If it's just a string field then issueInputBuilder.setFieldValue("customfield_10200", "string value"); should do the job.

For a label you need a list of strings there - to be sure just check the schema of that field.

issueInputBuilder.setFieldValue("customfield_10200", ImmutableList.of("label1", "label2"));

Tested and the code above works fine for me.

The best documentation for JRJC is the code itself + integration tests ;).

1 vote
Pedro Perez May 5, 2014

Anyone? Just trying to create an issue with a custom field, whose type is "label". I can't find a straightforward way to do it using the Java rest client. I'm very close to scrapping the rest client altogether.

sd-qa-jira-administrator December 20, 2017
// I found it after a long fight: Labels are given as array of "simple" values (display-names) only, no map:
// Assume String value = "Label1,Label2,Label3";
// and builder is an already well-formed IssueInputBuilder...
// Then, this work for me:
 List<String> fieldListlabel = new ArrayList<String>();
 String[] labels = value.split(",");
 for (String aLabel : labels) {
  if (aLabel == null || aLabel.isEmpty()) {
   continue;
  }
  fieldListlabel.add(aLabel);
 }
 builder.setFieldValue("customfield_11209", fieldListlabel);
// ...

 

Did you have a hint for creating an issue withcustom field of type "option-with-child" i.e., cascading selection field?

I am fiting for it now... it seams, I am loosing ... F1!

Thank you.

PS: Following Code did not work for me:

 ComplexIssueInputFieldValue headOpt = ComplexIssueInputFieldValue.with("value", "TV");
 ComplexIssueInputFieldValue tailOpt = ComplexIssueInputFieldValue.with("child", ComplexIssueInputFieldValue.with("value", "ARD"));
 Set<ComplexIssueInputFieldValue> cascade = new HashSet<ComplexIssueInputFieldValue>();
 cascade.add(tailOpt);
 cascade.add(headOpt);
 builder.setFieldValue("customfield_11207", cascade);
TAGS
AUG Leaders

Atlassian Community Events