Abstract

This code snippet unchecks a specific value of a standard or custom multi-valued type field (typically a multi-select field). The multi-valued fields can either be a collection of objects or a set of values. While unchecking all is easy (set the field with a blank value), unchecking only a particular option/value requires code. 

Logic

Iterate over the array of selected options and add them into a new array ignoring the option that needs to be unchecked.

Snippet

For multi-select fields:

//Retain all options ignoring the option that needs to be unchecked
def newValues = issue.get("<Name of the field>").findAll{
  it.getValue() != "<Value of the option to uncheck>"
}
return newValues
Placeholders
PlaceholderDescriptionExample
<Name of the field>Name of the field of type Checkboxes/Select list(multiple choices)Tasks list
<Value of the option to uncheck>Value of the option.Verification done

For multi-versions/users/components/groups fields (e.g. Fix Version/s):

//Retain all options ignoring the option that needs to be unchecked
def newValues = issue.get("<Name of the field>").findAll{
  it.getName() != "<Value to uncheck>"
}
return newValues
Placeholders
PlaceholderDescriptionExample
<Name of the field>Name of the multi-value fieldversions
<Value to uncheck>Value of the field.5.0.0

For Labels field:

//Retain all options ignoring the option that needs to be unchecked
def newValues = issue.get("<Labels field>").findAll{
  it.getLabel() != "<Label to remove>"
}
return newValues
Placeholders
PlaceholderDescriptionExample
<Labels field>Name of the Labels fieldLabels
<Label to remove>Label to be removedMerged

Examples

The output of the code is an array of objects which you could use in a Groovy expression to remove a particular option from the selected options of a field in one of the Set Field Value post-functions and the Create issue post-function under Set fields of new issue section.

References

Related articles


Related issues