0. Get the Projectrak Status field id
First of all is necessary to obtain the Projectrak “Status” and “End date” field ids from the Projectrak Field manager.
In the following example the id are: 42288 and 42286
1. Create an Automation rule
Go to: Settings \ System \ Global Automation, and create a new rule.
You can also access with a direct link, just replacing <your_instance> with yours:
https://<your_instance>.atlassian.net/jira/settings/automation
2 . Rule step: configure a trigger
Create a new trigger → Scheduled
Select the basic section
Choose your specific time: in this case every day at 06:00 AM
3. 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 the last 2 steps described at 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“
4. Rule step: get the “Off track” status id
Add component → New action → Send web request
Web request URL: https://profields-cloud.deiser.com/items/fields/<status_field_id>?query=Off track
* Replace the <status_field_id> with the one obtained in step 1.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
5. Rule step: store the Status id in a variable
Add component → New Action → Create variable
Variable name: projectrakOfftrackStatusId
Smart value: {{#webResponse.body.values}}{{id}}{{/}}
6. Rule step: generate a base64 authentication string for Jira
If you don’t have a Jira API token yet, please go to this page to generate it.
If you have already one, you can reuse it.
Use a Linux terminal:
echo -n JIRA_USER_EMAIL:JIRA_API_TOKEN | base64
* For Windows terminal, please refer this link.
7. Rule step: get all Jira projects
Add component → New action → Send web request
Web request URL: https://<your_instance>.atlassian.net/rest/api/3/project
Headers:
Content-Type: application/json
Authorization: Basic <base64 authentication string from previous step>
HTTP method: GET
Web request body: Empty
Check: Delay execution of subsequent rule actions until we've received a response for this web request
8. Rule step: iterate each project
Add component → New branch → Advanced branching
Smart value: {{webResponse.body}}
Variable name: project
9. Rule step: get each Projectrak “end date” field value
Add component → New action → Send a web request
Replace <field_id> using your field id. You can get this id from the Field manager.
Web request URL: https://profields-cloud.deiser.com/values/projects/{{project.id}}/fields/<endDate_field_id>
* Replace the <endDate_field_id> with the one obtained in step 1.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
Check: Continue running the rule even if the request response is not successful (i.e. non-200 response)
10. Rule step: store the Projectrak field value in a variable
Add component → New action → Create variable
Variable name: endDateValue
Smart value: {{webResponse.body.value.value}}
11. Rule step: compare dates between the current date and end-date of Projectrak.
Add component → New condition → Advanced compare condition
First value: {{endDateValue}}
Condition: less than
Second value: {{now.format("yyyy-MM-dd")}}
12. Rule step: get all issues from a project and unresolved
Add component → New action → Lookup issues
JQL: project={{project.id}} and resolution is empty
13. Rule step: compare the numbers of issues in unresolved
Add component → New condition → Advanced compare condition
First value: {{lookupIssues.size}}
Condition: does not equal
Second value: 0
14. Rule step: update project status field
Add component → New action → Send a web request
Replace <field_id> using your field id. You can get this id from the Field manager.
Web request URL: https://profields-cloud.deiser.com/values/projects/{{project.id}}/fields/<field_id>
Headers:
Content-Type: application/json
Authorization: Bearer {{projectrakJwt}}
HTTP method: POST
Web request body: Custom data
Custom data: {{projectrakOfftrackStatusId}} is the item ID of status field from Projectrak
{ "value": {{projectrakOfftrackStatusId}} }
Check: Delay execution of subsequent rule actions until we've received a response for this web request
Check: Continue running the rule even if the request response is not successful (i.e. non-200 response)