Code snippet to add user(s) selected in a multi-user picker field to a Jira group.

Requirement:

Nunjucks code snippet to add the user(s) selected in a multi-user picker field to a Jira group.

Solution:

{%set users = issue.fields.customfield_10043 | field("_accountId")%} {% for user in users %} {{ "https://ABC/rest/api/3/group/user" | callRest(query={"groupId":"XYZ"}, body ={ "accountId": user }, verb=("POST"), options = { headers: { "authorization": "Basic XXXXX" } })}} {% endfor %}

Replace:

  1. 10043 in line #1 with the ID of the "User Picker (multiple users)" custom field [the users selected in this field will be added to the Jira group.

  2. ABC in line #3 with the base URL of your Jira Cloud instance.

  3. XYZ in line #3 with the ID of the Jira group to which you would like to add the users. You can easily get the group ID using the Lookup group… feature of Nunjucks Template Editor.

  4. XXXXX in line #9 with your API token - check this.

 

  • The above script uses the callRest JMWE Nunjucks filter and this Atlassian Jira Cloud REST API.

  • This Nunjucks code can be added in JMWE post-functions (that can be added in workflows and JMWE Actions: Event-based or Scheduled or Shared Actions)

  • If this script is added in a JMWE post-function that is added on the create transition of a workflow, select the checkbox “Delay the execution of this post-function” under “Delayed execution” and select a delay of 3 seconds.

 

References