Abstract
This code snippet retains the only value of a multi-valued type field which can either be an array of objects or a set of values. This snippet is useful when you know that the array has only one value and hence by applying the first or last methods you can retain it.
Logic
Use the first/last filter to get the only object of the field and access the specific field for the required value.
Snippet
Code Block | ||||
---|---|---|---|---|
| ||||
{# Apply the first/last filter to the array of objects. Upon that apply the field filter #} {{ issue.fields["<Multi-valued field>"] | <filter> | field("<Value>") }} |
...
Set a field in one of the Set field value post-functions or the Create issue post-function under the Set fields of new issue section. Examples:
- Assign the issue to the author of the last comment
Code Block language js linenumbers true {{ issue.fields.comment.comments | last | field("author.nameaccountId") }}
Name of the issue link type of the only linked issue to the current issue
Code Block language js linenumbers true {{ issue.fields.issuelinks | first | field("type.name") }}
- Assign the issue to the author of the last comment
Send an email to the first user of a Multi-user picker field in the Email issue post-function
Code Block language js linenumbers true {{ issue.fields["Multi-user picker"] | first | field("nameaccountId") }}
References
- How to insert information using Nunjucks annotations
- Accessing the fields of an issue
- first filter,last filter and field filter
...