Set issue watchers from a Projectrak field on issue creation
This example describes the automatic set of the issue watcher users when it’s created based on the project component type.
The issue watchers to set are stored in a Projectrak field as source.
In the case described here, when an issue is created with a “Software” Component field value, the issue watchers will be set to the members from a Projectrak user field called “Software team”.
0. Rule context
The project(s) that the Automation rule will run on issue creation, must have some Components created, such as the following:
The issue creation screen for that project(s), must have the Components field added and visible.
A Projectrak user (multiple select) must be created from the Projectrak field manager.
Then, get the field id which is: 262552, in this example.
Finally set member for that field in the desired project(s)
1. Create an Automation rule
Go to: Settings \ System \ Global Automation, and create a new rule.
You can also go there with a direct link, just replacing <your_instance> with yours:
https://<your_instance>.atlassian.net/jira/settings/automation
You can restrict the scope of this rule to run only for the desired project in the "Rule details" section.
2 . Rule step: configure a “Issue created” trigger
3. Rule step: configure a condition based on a issue field
Add component → New condition → Issue fields condition
Field: Components
Condition: equals
Second value: Software
4. Get the Projectrak authorization token and store it in a variable
If you don’t have a Projectrak API token yet, follow the first steps (1 to 5) of the link below.
If you have already got it, you can reuse it.
Add to the rule the last 2 steps described in this link: https://deiser-apps.atlassian.net/wiki/spaces/PROJECTRAKCLOUD/pages/1641490/How+to+create+a+Projectrak+authorization+in+Automation+for+Jira?src=search
“6. Get the Projectrak JWT”
“7. Store the JWT in a variable“
5. Rule step: get the “Software team” field members from the project data
Add component → New action → Send web request
Replace the <field_id> with the one obtained in step 0
Web request URL: https://profields-cloud.deiser.com/values/projects/{{issue.project.id}}/fields/<field_id>
Headers:
Content-Type: application/json
Authorization: Bearer {{projectrakJwt}}
HTTP method: GET
Web request body: Empty
Check: Delay execution of subsequent rule actions until we've received a response for this web request
6. Rule step: iterate each project
Add component → New branch → Advanced branching
Smart value: {{#webResponse.body.value}}{{value}}{{/}}
Variable name: memberId
7. Get a Jira API token
If you don’t have a Jira API token yet, please go to this page and generate it:
If you have already one, you can reuse it.
Once created the Jira API token, open a Linux terminal and execute this command to generate a base64 authentication string:
echo -n JIRA_USER_EMAIL:JIRA_API_TOKEN | base64
For Windows powershell, please refer this link.
Copy the result string for the next step, please.
8. Rule step: set the issue watchers
Add component → New action → Send web request
Web request URL: https://<your_instance>.atlassian.net/rest/api/3/issue/{{issue.id}}/watchers
Headers:
Accept: application/json
Content-Type: application/json
Authorization: Basic <Jira base64 authentication string>
HTTP method: POST
Web request body: Custom data
Custom data: "{{memberId}}"
And that’s pretty much it!