ScriptRunner/Automation for Calculating End Date based on estimates and Updating Epic Estimations

Maggie Tokarzewska
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 11, 2024

I'm encountering issues with implementing automation using ScriptRunner in Jira to calculate the end date based on custom estimations and to update epic estimations based on child issues. Below are the details and the scripts I have tried:

Requirements:

  • Working Days: 5 working days a week (Monday-Friday)
  • Working Hours: Each day has 7 working hours
  • Total Working Days: Calculated as (Dev Estimations + QA Estimations + Tech Art Estimations) / 7, rounded up.
  • End Date Calculation: Start Date + Total Working Days, excluding weekends.
  • Epic Estimations: Update if the total of child issues' estimations exceeds the current epic estimations.

    Zrzut ekranu 2024-07-11 o 17.20.16.pngZrzut ekranu 2024-07-11 o 17.20.23.png


Attempted Approach without ScriptRunner (Using Jira Automation):

  1. Trigger: Field value changed
    • Fields: Start Date, Dev Estimations, QA Estimations, Tech Art Estimations
  2. Conditions:
    • Issue fields condition:
      • Field: Start Date
      • Condition: is not empty
  3. Actions:
    • Create variable to calculate totalHours:
      • Variable name: totalHours
      • Value:textCopy code

        {{#=}}issue.fields["Dev Estimations"].toNumber() + issue.fields["QA Estimations"].toNumber() + issue.fields["Tech Art Estimations"].toNumber(){{/}}

    • Create variable to convert totalHours to totalWorkingDays:
      • Variable name: totalWorkingDays
      • Value:textCopy code

        {{#=}}ceil(totalHours / 7){{/}}

    • Create variable to calculate interimEndDate:
      • Variable name: interimEndDate
      • Value:textCopy code

        {{#=}}{{issue.fields["Start Date"].plusDays(totalWorkingDays)}}{{/}}

  4. Conditions and Actions to Adjust for Weekends:
    • Condition: If interimEndDate is Saturday
      • Advanced compare condition:
        • First value: {{interimEndDate.toDate("e")}}
        • Condition: equals
        • Second value: 6
      • Action: Edit issue fields to set End Date to {{interimEndDate.plusDays(2)}}
    • Condition: If interimEndDate is Sunday
      • Advanced compare condition:
        • First value: {{interimEndDate.toDate("e")}}
        • Condition: equals
        • Second value: 7
      • Action: Edit issue fields to set End Date to {{interimEndDate.plusDays(1)}}
    • Default Action: If interimEndDate is not a weekend
      • Edit issue fields:
        • Field: End Date
        • Value: {{interimEndDate}}

Any help to resolve these issues or to identify where the scripts might be failing would be greatly appreciated!

Thank you!

1 answer

0 votes
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 11, 2024

Hi @Maggie Tokarzewska -- Welcome to the Atlassian Community!

First thing, I am not currently using ScriptRunner and so my suggestions will focus on your Jira Automation rule shown.

 

You note there are challenges with your solutions, but you do not describe what they are.  What is not working as you expect with your rule?

Until we know those challenges...some observations for your rule are:

 

The {{#=}} ... {{/}} syntax is a math operation, and it is not used for date incrementing.  To increment a date value, just use the plus / minus functions, such as:

{{issue.myDateField.plusDays(someValue)}}

When someValue is a variable, that needs to be converted to a number for use in the functions:

{{issue.myDateField.plusDays(someValue.asNumber)}}

 

I have observed using fields to be problematic in rule smart values.  Instead I recommend using either the exact smart value for the field, or its custom field id.  To correctly identify those, please use this how-to article: https://support.atlassian.com/cloud-automation/docs/find-the-smart-value-for-a-field/

The basic steps are:

  • identify an example issue with your fields
  • using a browser tab, perform a REST API lookup of the issue
yourJiraURL/rest/api/2/issue/yourExampleIssueKey?expand=names
  • Now search for your field, by name, on the page to find the correct smart value and / or custom field id to use.  Note that smart values are name, spacing, and case-sensitive, and so using an incorrect one is substituted with null, often failing to work as expected.

 

 

The rule adjustments for weekends may not work as you expect, as they only account for the end point falling on a weekend day and not any multiple weeks that could be spanned by the estimates.

An alternative approach is to explicitly increment by business days instead:

{{issue.Start date.plusBusinessDays(totalWorkingDays.asNumber)}}

Even with this approach, this will not handle any non-working holidays.  Those will need either a much more complex rule or another solution approach.

 

Kind regards,
Bill

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events