cannot set custom field with array of options Edited

with JIRA v7.1.9#71013  and JIRA rest API 4.0.0

 

Scala code:

case class JiraFieldDefinition(id: Long, fullIdForSave: String, typeName: String, itemsTypeIfArray: Option[String])
and then processing for custom fields:
case _ =>
val fieldSchema = customFieldResolver.getId(fieldName)
if (fieldSchema.isDefined) {
val fullIdForSave = fieldSchema.get.fullIdForSave
val valueWithProperJiraType = getConvertedValue(fieldSchema.get, value)
issueInputBuilder.setFieldValue(fullIdForSave, valueWithProperJiraType)
}

def
getConvertedValue(fieldSchema: JiraFieldDefinition, value: Any) : Any = {
fieldSchema.typeName match {
case "array" if fieldSchema.itemsTypeIfArray.get == "string" => List(value).asJava
case "array" if fieldSchema.itemsTypeIfArray.get == "option" =>
List(
new CustomFieldOption(fieldSchema.id, null, value.toString, Seq().toIterable.asJava, null)
).asJava
case "number" => ValueTypeResolver.getValueAsFloat(value)
case _ => value
}
}

so, to summarize: this code goes through custom fields. it works fine for a custom "label" where an array of strings is expected.  ( case "array" if fieldSchema.itemsTypeIfArray.get == "string" )

but it fails for a custom field called "custom_checkbox_1" with ID 10102 and customId=customfield_10102.

(see the second "case"  for array+option).

the error I get is:

ErrorCollection{status=400, errors={customfield_10102=Invalid value '10102' passed for customfield 'custom_checkbox_1'.}, errorMessages=[]}

 

1 answer

1 accepted


found a solution. had to use


ComplexIssueInputFieldValue.`with`("value", value.toString)


instead of


new CustomFieldOption(fieldSchema.id, null, value.toString, Seq().toIterable.asJava, null)

 

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published yesterday in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

56 views 0 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you