Abstract
This code snippet checks the 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.
...
Code Block | ||||
---|---|---|---|---|
| ||||
//Run a loop on all the selected options of the field and find the desired option return (issue.get("<Name of the field>").find any{ it.getValue() == "<Value of the field>"} != null) |
Placeholders
Placeholder | Description | Example |
---|---|---|
| Name of the multi-select field |
|
<Value of the field> | Value of the option | Verification done |
...
Code Block | ||||
---|---|---|---|---|
| ||||
//Run a loop on all the selected options of the field and find for the desired object return (issue.get("<Name of the field>").findany { it.getName() == "<Name of the desired version>"} != null) |
Placeholders
Placeholder | Description | Example |
---|---|---|
<Name of the field > | Name of the multi-valued version field | fixVersions |
<Name of the desired version> | Name of the version to find | 2.0 |
...
Code Block | ||||
---|---|---|---|---|
| ||||
//Run a loop on all the selected labels of the field and find for the desired label return (issue.get("<Name of the field>").findany { it.getLabel() == "<Desired label>"} != null) |
Placeholders
Placeholder | Description | Example |
---|---|---|
<Name of the field > | Name of the labels field | labels |
<Desired label> | Label to find | Use-case |
...
The output of the code is a boolean value (true
or false)
which you could use to conditionally execute a Post-function/Condition/Validator or Unlink issues:
Check the issue has been flagged
Code Block language groovy linenumbers true return (issue.get("Flagged").findany { it.getValue() == "Impediment"} != null)
Check the issue has a label
Server
Code Block language groovy linenumbers true return (issue.get("Labels").findany { it.getLabel() == "Server"} != null)
Check the issue has
5.0.0
as an Affects Version/sCode Block language groovy linenumbers true return (issue.get("versions").findany { it.getName() == "5.0.0"} != null)
References
- Variables used in a Groovy expression
- Issue interface
- Accessing User-created custom fields
- Groovy Documentation
...