Versions Compared

Key

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

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

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 currently selected options and add them into a new array ignoring the option that needs to be unchecked.

Snippet 

For multi-select fields:

Code Block
languagejs
linenumberstrue
{# Dump options that do not match the search  - Requires the "Treat as JSON" option #}
{{ issue.fields['<Name of the field>'] | filter({value:"<Value of the option to uncheck>"} , true ) | dump }}
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):

Code Block
languagejs
linenumberstrue
{# Dump values that do not match the search  - Requires the "Treat as JSON" option #}
{{ issue.fields['<Name of the multi-valued field>'] | filter({name:"<Value to uncheck>"} , true ) | dump }}
Placeholders
PlaceholderDescriptionExample
<Name of the field>Name of the multi-valued fieldversions
<Value to uncheck>Value of the field.5.0.0

For Labels field:

Code Block
languagejs
linenumberstrue
{# Dump labels that do not match the search  - Requires the "Treat as JSON" option #}
{{ issue.fields['<Labels field>'] | filter("<Label to remove>" , true ) | dump }}
Placeholders
PlaceholderDescriptionExample
<Labels field>Name of the Label fieldLabels
<Label to remove>Label to be removedMerged

Examples

The output of this code snippet is an array of objects which you could use to remove a particular option from the selected options of a field in one of the Set Field Value post-functions.

Note

These code snippets require "Treat as JSON" option to be selected

  • Remove the reporter from the JIRA service desk customers

    Code Block
    languagejs
    linenumberstrue
    {{ issue.fields['Service Desk Customers'] | filter({name:issue.fields.reporter.name} , true ) | dump }}


  • Clear the option "To Print" after the print has been generated

    Code Block
    languagejs
    linenumberstrue
    {{ issue.fields['Documents processing'] | filter({name:"To Print"} , true ) | dump }}


  • Remove the label "Merged" when QA re-opens a ticket that has been merged into master and handed over to QA.

    Code Block
    languagejs
    linenumberstrue
    {{ issue.fields['Labels'] | filter({name:"Merged"} , true ) | dump }}


References

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

...