Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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
languagejs
linenumberstrue
//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

PlaceholderDescriptionExample
<Multi-valued field name>Name of the multi valued fieldwatches
<Condition>Condition to meet for the value to be filteredit.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
    languagejs
    linenumberstrue
    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
    languagejs
    linenumberstrue
    def newValues = issue.get("Request Participants").findAll{
      it.getName() != currentUser.getName()
    }
    return newValues


References

Filter by label (Content by label)
showLabelsfalse
max5
spacesKB
showSpacefalse
sortmodified
reversetrue
typepage
cqllabel = "jmwe-groovy" and type = "page" and space = "KB"
labelsjmwe-nunjucks jmwe-cloud

...