Calculate Project planned duration based on two dates
- 1 00. Requisites
- 2 01. Configure the rule trigger
- 3 02. Create a Projectrak outgoing webhook
- 4 03. Configure the rule steps
- 4.1 Step 1. Getting the project id
- 4.2 Step 2. Check if the start date is edited
- 4.3 Step 3. Check if the end date is edited
- 4.4 Step 4. Check if the rule should be executed
- 4.5 Step 5. If the rule should be executed continue
- 4.6 Step 6. Get the Projectrak authorisation JWT
- 4.7 Step 7. Get the value of the field Start date in the project
- 4.8 Step 8. Set the value in a variable
- 4.9 Step 9. Get the value of the field Start date in the project
- 4.10 Step 10. Set the value in a variable
- 4.11 Step 11. Calculate the planned duration days
- 4.12 Step 12. Set the value in the Planned Duration field
00. Requisites
For the execution of this rule, there must be 3 previously created fields.
Start date: Date field
End date: Date field
Planned Duration (natural days): Number field
01. Configure the rule trigger
Create a new trigger → Incoming webhook
Copy the autogenerated Webhook URL and the Secret from the incoming webhook.
Set the field “Execute this automation rule with“ with “No work items from the webhook“
02. Create a Projectrak outgoing webhook
In order to the rule will be executed when a project field changed we need to create a outgoing webhook pointing to the Automation Incoming webhook url.
Go to: Administration → Apps → Projectrak → Projectrak outgoing webhooks
Create a new webhook
Set the name of the webhook and the url with the previously copied url from the Automation incoming webhook and save.
Because of this change (https://support.atlassian.com/cloud-automation/docs/configure-the-incoming-webhook-trigger-in-atlassian-automation/ ), you have to add a slash and the secret at the end of the Webhook URL (https://URL/SECRET)
Now you have linked Projectrak with Automation rule.
Now, when a Projectrak field value is edited in any project, the Automation rule will be triggered.
03. Configure the rule steps
You can see the information that will be sent to the rule every time a field is updated in a project here: https://deiser-apps.atlassian.net/wiki/spaces/PROJECTRAKCLOUD/pages/48824321
Step 1. Getting the project id
Create an action: Create variable
Variable name: projectId
Smart value: {{webhookData.project.id}}
Step 2. Check if the start date is edited
Create an action: Create variable
Variable name: hasStartDate
Smart value: {{#webhookData.fields}}{{#if(equals(name,"Start date"))}}{{value.current}}{{/}}{{/}}
Step 3. Check if the end date is edited
Create an action: Create variable
Variable name: hasEndDate
Smart value: {{#webhookData.fields}}{{#if(equals(name,"End date"))}}{{value.current}}{{/}}{{/}}
Step 4. Check if the rule should be executed
Create an action: Create variable
Variable name: shouldExecute
Smart value: {{or(hasStartDate.isNotEmpty(),hasEndDate.isNotEmpty())}}
Step 5. If the rule should be executed continue
Create a condition: Advanced compare condition
First value: {{shouldExecute}}
Condition: equals
Second value: true
Step 6. Get the Projectrak authorisation JWT
Add the steps explained here: How to create a Projectrak authorization in Automation for Jira
Step 7. Get the value of the field Start date in the project
Create an action: Send web request
Web request URL: https://profields-cloud.deiser.com/values/projects/{{projectId}}/fields/<START_DATE_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
Step 8. Set the value in a variable
Create an action: Create variable
Variable name: startDate
Smart value: {{webResponse.body.value.value}}
Step 9. Get the value of the field Start date in the project
Create an action: Send web request
Web request URL: https://profields-cloud.deiser.com/values/projects/{{projectId}}/fields/<END_DATE_FIELD_ID>
Headers:
Content-Type: application/json
Authorization: {{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
Step 10. Set the value in a variable
Create an action: Create variable
Variable name: endDate
Smart value: {{webResponse.body.value.value}}
Step 11. Calculate the planned duration days
Create an action: Create variable
Variable name: plannedDurationDays
Smart value: {{startDate.toDate("yyyy-MM-dd").diff(endDate.toDate("yyyy-MM-dd")).days}}
Step 12. Set the value in the Planned Duration field
Create an action: Send web request
Web request URL: https://profields-cloud.deiser.com/values/projects/{{projectId}}/fields/<PLANNED_DURATION_FIELD_ID>
Headers:
Content-Type: application/json
Authorization: {{projectrakJwt}}
HTTP method: POST
Web request body: Custom
Custom data: {"value": "{{plannedDurationDays}}"}
Check: Delay execution of subsequent rule actions until we've received a response for this web request
This example uses an incoming webhook trigger and two date fields to calculate the period but more options can be used.
I.e. You can calculate the remaining time of a project with a scheduled trigger that executes every day and the end date of the project and the current date (see Jira smart values - date and time )