Calculate and fetch a subset of values of a multi-valued field based on a condition
Abstract
This code snippet filters values from a collection of objects based on a condition.
Logic
Iterate over the collection of objects and filter values that meet the condition
Snippet
//Find the array of values that satisfy the condition and return it
return issue.get("<Multi-valued field name>").findAll{
//Write the condition
<Condition>
}Placeholders
Placeholder | Description | Example |
|---|---|---|
| Name of the multi-valued field |
|
| Condition to meet for the value to be filtered |
|
Examples
The output of this snippet is a subset of the existing values of a multi-valued field which you could use in a Groovy expression, to show a subset of the existing values of a multi-select custom field type that satisfy a condition. For example:
Show just the customers watching the issue in a user picker field. For this, you will need to create a Calculated Multi-user select custom field type and configure it with the following Groovy formula.
return issue.get("watches").findAll{ it.isInProjectRole("Service Desk Customers",issue.get("project") ) }Display a custom text field with the text "Unreleased" if there is at least one Fix Version/s that is not released.
issue.fixVersions.any{!it.isReleased()}?"Unreleased":null
