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
Code Block | ||||
---|---|---|---|---|
| ||||
//Define an array to find and store the filtered values def newValues = issue.get("<Multi-valued field name>").findAll{ //Write the condition <Condition> } return newValues |
Placeholders
Placeholder | Description | Example |
---|---|---|
> | Name of the multi valued field | watches |
> | Condition to meet for the value to be filtered | it.getName() != issue.get("reporter").getName() |
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
Set a multi-valued field to a subset of the existing values in one of the Set field value post-functions and the Create issue post-function under Set fields of new issue section. Example: Set a Multi-user picker type field to the users in the Watchers field excluding the Reporter of the issue:
Code Block language js linenumbers true def newValues = issue.get("watches").findAll{ it.getName() != issue.get("reporter").getName() } return newValues
Send an email to all the users of the Request Participants when a meeting schedule has been changed, except to the current user in the Email issue post-function
Code Block language js linenumbers true def newValues = issue.get("Request Participants").findAll{ it.getName() != currentUser.getName() } return newValues
References
- Variables used in a Groovy expression
- Issue interface
- Accessing the fields of an issue
- Groovy Documentation
Related articles
Filter by label (Content by label) | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
...