2. Projectrak list field from Jira groups: options deletion
This article describes how to remove Projectrak list field options automatically using an Automation rule, if removed groups from the Jira instance.
- 1 Step 0. Get the Projectrak List field Id
- 2 Step 1. Create an Automation rule
- 3 Step 2 . Rule step: configure a trigger
- 4 Step 3. Rule step: generate a base64 authentication string for Jira
- 5 Step 4. Rule step: get all Jira groups
- 6 Step 5. Rule step: store the list field option custom ids in a variable
- 7 Step 6. Rule steps: get the Projectrak authorization token and store it in a variable
- 8 Step 7. Rule step: get the Projectrak list field options
- 9 Step 8. Rule step: iterate each Projectrak list field option
- 10 Step 9. Rule step: check if the Jira group is already in the Projectrak list field options
- 11 Step 10. Rule step: remove the Projectrak list field option
Step 0. Get the Projectrak List field Id
First of all, get the Projectrak “List (multiple select)” field Id from the Projectrak Field manager.
In this example, the id is “433066”.
Step 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
Step 2 . Rule step: configure a trigger
Create a new trigger → Scheduled
Select the basic section
Choose your specific time: in this example every day at 06:00 AM
Step 3. Rule step: generate a base64 authentication string for Jira
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.
Open a Linux terminal and execute this command:
echo -n JIRA_USER_EMAIL:JIRA_API_TOKEN | base64For Windows powershell, please refer this link.
Copy the result string, please.
Step 4. Rule step: get all Jira groups
Add component → New action → Send web request
Replace the <max_results> with the max number of existing groups in the Jira instance. For example: 100.
Web request URL: https://<your_instance>.atlassian.net/rest/api/3/groups/picker?maxResults=<max_results>
Please, check all Jira groups are returned by pasting this URL in a browser tab. In case, there’re more groups than max results, increase this limit. You can refer to the Atlassian reference here.
HTTP method: GET
Web request body: Empty
Check: Delay execution of subsequent rule actions until we've received a response for this web request.
Headers:
Content-Type: application/json
Authorization: Basic <Jira base64 authentication string>
Step 5. Rule step: store the list field option custom ids in a variable
Add component → New Action → Create variable
Variable name: jiraGroupIds
Smart value: {{webResponse.body.groups.groupId.asJsonStringArray}}
Step 6. Rule steps: 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: Setup - ⚙️ Create a Projectrak authorization
“6. Get the Projectrak JWT”
“7. Store the JWT in a variable“
Step 7. Rule step: get the Projectrak list field options
Add component → New action → Send web request
Replace the <list_field_id> with the one obtained in step 0
Replace the <max_items> with the max number of existing groups in the Jira instance. For example: 100.
Web request URL: https://profields-cloud.deiser.com/items/fields/<list_field_id>?size=<max_items>
HTTP method: GET
Web request body: Empty
Check: Delay execution of subsequent rule actions until we've received a response for this web request.
Headers:
Accept: application/json
Authorization: Bearer {{projectrakJwt}}
Step 8. Rule step: iterate each Projectrak list field option
Add component → New branch → Advanced branching
Smart value: {{webResponse.body.values}}
Variable name: projectrakFieldOption
Step 9. Rule step: check if the Jira group is already in the Projectrak list field options
Add component → New condition → {{smart values}} condition
First value: {{jiraGroupIds}}
Condition: does not contains
Second value: {{projectrakFieldOption.customId}}
Step 10. Rule step: remove the Projectrak list field option
Add component → New action → Send a web request.
Web request URL: https://profields-cloud.deiser.com/items/{{projectrakFieldOption.id}}
HTTP method: DELETE
Web request body: Empty
Headers:
Authorization: Bearer {{projectrakJwt}}
And that’s all folks!