Automation For Jira - How to validate "Assignable user" permission when cloning issues


Platform Notice: Data Center - This article applies to Atlassian products on the Data Center platform.

Note that this knowledge base article was created for the Data Center version of the product. Data Center knowledge base articles for non-Data Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

When working with complex automation rules that are cloning issues in another target project, using an existing assignee as an input value often comes as a challenge because the value is controlled by the end user, and the current assignee in the source project does not necessarily have "Assignable user" permission in the target project. In cases like those, the permission validation will fail, and the new issue will not be created, and the rule will fail to complete. To overcome this situation, we need to first validate the appropriate permissions before action.

Environment

  • Jira Data Center Only (not applicable to Server licenses)
  • Applicable Jira / A4J (Automation for Jira) versions which include the Create Variable action:
    • Jira 9.11.0 and any higher version (this Jira version ships with A4J 9.0.1)
    • OR Jira 8.20.0 and any higher version, in combination with A4J 9.0.1 or any higher version

Diagnosis

The lack of "Assignable User" permission problem can be identified in the audit logs of the automation rule. There is always an "Error creating issue" entry with following content "User 'username' cannot be assigned issues. (assignee)".

Solution

  • To achieve our new requirements, we will utilize a Send Web Request action, call Jira REST API, and validate whether the user we intend to use has "Assignable User" permission in the target project.

  • Once we have the webhook response, we will parse the body for results. If the response is an empty collection, that means that the validated user has no appropriate "Assignable User" permission in the target project. With this, we will use conditional logic on the Assignee field in the Clone Issue action.

Rule configuration

Here is a very simplified rule that can be used as an example.  The rule will need to be configured as follows:

  • Add the Manual trigger. Optionally, restrict the trigger based on the group.
  • Add the action Create Variable. The purpose of this variable is to hold the user that needs to be checked. The value of this variable can come from {{issue.assignee}} or {{issue.customfield_XXXXX}}, depending on your exact requirements. In this example, we will attempt to clone the issue and set the assignee to the value of a user picker (single user) custom field which can be accessed via the smart value customfield_XXXXX, where XXXXX is the Custom Field ID which can be found as per How to find a Custom Field ID.
    • Variable Name: issueAssigne
    • Smart value

      {{issue.customfield_XXXXX}}
  • Add the action Send Web Request with the following configuration: 
    • Webhook URL: JIRA_BASE_URL/rest/api/2/user/assignable/search?username={{issueAssigne}}&project=PKEY
      • Replace JIRA_BASE_URL with the base URL of your Jira instance.
      • Replace PKEY with the target project key.
    • Headers:

      • Authorization header with Bearer token. For on details how to create a PAT token please refer to the following article: Using Personal Access Tokens.

    • HTTP Method: GET
    • Webhok Body: Empty
    • Wait for Response: Checked
  • Add Clone Issue  action with the following configuration:
    • Project: Chose a target project.

    • Issue Type: Chose appropriate Issue Type.
    • Chose fields to set: Assignee
    • Assingee: Set Value

      • The following options set the assignee of the cloned issue to the user stored in the smart value issueAssigne if the previous web request returns the user in the body (which means that the user has the assignable permission) or leave it unassigned by passing an empty string.

        {{if(webhookResponse.body.size.gt(0), issueAssigne, "")}}
      • To assign the issue to a specific user in case the issueAssigne doesn't have the required permission, you can add the username of the designated user like this.

        {{if(webhookResponse.body.size.gt(0), issueAssigne, "admin")}}

Screenshot showing the rule

Create Variable Action:

Send Web Request Action:

Clone Issue Action:

Jira Data Center - Rest API

For additional information and to get started with Jira Data Center Rest API, read the reference documentation: Jira Server platform REST API] and Atlassian Developer - Rest API.
The Jira Software and Jira Service Management applications have REST APIs for their application-specific features, like sprints (Jira Software) or customer requests (Jira Service Management).


Last modified on Oct 22, 2024

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.