How to set and get user properties in automation
Platform Notice: Cloud - This article applies to Atlassian products on the cloud platform.
Summary
Currently, there is no way to set/get a global attribute for either a user/project/issue using Jira. This knowledge-based article provides a way to do that using REST API and Jira automation.
Environment
Jira Cloud.
Solution
Example Scenario
In a typical business scenario, the users should be able to set their status to Out of Office, and when their status is set to OOO, no issues should be assigned to them
Suggested Solution
The Jira Cloud REST API provides the following endpoints to set and get global attributes/properties for users/issues/projects.
Automation Rule (Setting User Property)
- A new custom field representing the user's status needs to be created using a single select custom field. The field should only have two options (Yes/No).
- The users would have to choose their current status from this drop-down and as soon as they make a choice, the automation rule will trigger and set the user property (*propUserAvailability*) based on the value of the drop-down custom field. This property would be accessible across the site wherever this user is present.
- The below-mentioned REST end-point is used to set the user property
https://your_site_name.atlassian.net/rest/api/3/user/properties/propUserAvailability?accountId={{initiator.accountId}}}
The following JSON body will be sent as the payload of the REST call.
{
"val": "{{issue.PH Flag.value}}",
"aid": "{{initiator.accountId}}"
}
val : This will store the user's choice that they made when setting their status.
aid : This will store the user's account ID who made that choice.
You will have to generate basic auth credentials for REST API by following steps 1-3 of this article https://developer.atlassian.com/cloud/jira/platform/basic-auth-for-rest-apis under the heading Supply basic auth headers and put the generated string in the Authorization header in the following format
Basic <base-64 encoded auth string>
Automation Rule (Getting User Property)
- This automation will be triggered when the issue is assigned to a user.
- The below-mentioned REST end-point is used to check whether the issue assignee has set the availability flag?
https://Your_site_name.atlassian.net/rest/api/3/user/properties/propUserAvailability?accountId={{issue.assignee.accountId}}
- Use the same credentials that you generated for the first rule and put the generated string in the Authorization header in the following format.
Basic <64-bit encoded auth string>
Create a smart variable to store the value of user property returned through the web response object.
{{webResponse.body.value.val}}
.
Since we don't have control over or the knowledge of who the next assignee will be by round robin method or balance workload method, therefore, we wait for the issue to be assigned and then check if the assignee has set the availability flag as OOO or not.
If the issue assignee has set the flag field to No (No represents OOO) then unassign the issue.