How to automate the addition based on many inputs?

Ryan Wolfe January 19, 2022

I have an issue that I can't seem to solve. 

Scenario: 

A user is creating a request and we have a checkbox list of items they can select 1 to all items, these represent tasks that they need to be completed in the request.

We then need an automation that goes through all the selected options adds different amounts to the Original Estimate and has the total number be the final outcome.


Issues:

  1. Whenever I try to list a series of if/else conditions OR even create many small independent automations, it seems that the value of the field I am adding to doesn't update so it just adds to what was there before the automation is ran. 
    1. Example:
      1. The setup 
        1. Original Estimate = 0 at the beginning
        2. There are two options selected
          1. Option 1 should be 1 hour
          2. Option 2 should be 1.5 hours
        3. I use if conditions to check if the options are selected.
        4. I use any number of ways to add a value, but the best is: {{#=}}{{timetracking.originalEstimateSeconds.plus(3600)}}/60{{/}}
        5. I update both Original Estimate and Remaining Estimate
      2. Expectation: it would hit the first one, change the value to 1 hour, hit the second, and add 1.5 hours to make it be 2.5 hours.
      3. What really happens: It changes the estimates to 1 hour in the first check, but then when it goes to the second, it still uses 0. So instead of adding the amount to 1 it adds it to 0 and moves on. This effectively makes it only be the value from the last check that is run. 
  2. When you try to add to an estimate field if you first add the number it will then multiply the entire amount by 60
    1. Example:
      1. Setup:
        1. The first run-through adds 60 (thinking it will be 60 minutes) 
          1. The estimate shows 1 hr
        2. In the second run-through, you want to add 1 more hour so you add 60 again 
      2. Expectation: After the second run-through, it would show 2 hours.
      3. What really happens: After the first, it takes the 60 multiplies by 60 equalling 3600 (how many seconds are in an hour). The second round takes 60, adds it to 3600 to get 3660 then multiplies by 60 again so you get 219600 which is 219600 which equals 1 week, 2 days, and 5 hours.

I was going to try to use Variables but there doesn't seem to be a way, that I can find, to dynamically update the value of a variable and have it then be pushed into a field.

All I need is to have a reliable way to check all options selected and add the corresponding hours to the estimates. Does anyone have any ideas on how to do this?

1 answer

1 accepted

1 vote
Answer accepted
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.
January 19, 2022

Hi @Ryan Wolfe 

For a question like this, please consider posting images of your rule and audit log, showing the details of the execution that does not work as you expect.  That context may help the community to offer suggestions.  Thanks!

Based on what you describe, I hypothesize a few things are happening:

  • When you edit a field, and then edit the same field again (in another condition) you are not first doing a re-fetch action to reload the data.  This could potentially walk-over prior results as the rule uses the data from the time of triggering to proceed.  One way to do what you describe is:
    • if/else with a condition
      • edit the issue field
      • re-fetch
    • if/else with a condition
      • edit the issue field
      • re-fetch
    • ...
  • Next, when you are repeatedly adding those numbers, consider that time values for tracking using your defined working hours and days of weeks in calculations.  So if you used the defaults of Monday-Friday and 8 hours/day you may not get what you expect unless you add the time all at once.
  • You note one of my concerns about automation's created variables: they cannot be edited.  (Here's a suggestion to improve that.)  The work-around is to use a pair of created variables and use one to update the other, recreating them as needed.  The key is this cannot happen in a branch which has more than one issue, or the processing happens asynchronously and wipes them out.

My suggestion: figure out a way just to count the options and then multiply, if possible for one single edit.

Kind regards,
Bill

Ryan Wolfe January 20, 2022

@Bill Sheboy how would one re-fetch? because I even tried making the if/else into separate automations and the same issue occurred which I would assume would mean I am re-fetching each time.

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.
January 20, 2022

Hi, Ryan.  There is a Re-fetch action to do that.  And yes, you would need to re-fetch after each edit.

Ryan Wolfe January 20, 2022

@Bill Sheboy  Thanks for the clarification, I just did a test with a simple number field and the same behavior occurred even with the re-fetch. It ignores the previous "if" statement adding a value and only does the last one that is run. I did put a re-fetch at the end of both if/else conditions. 

2022-01-20 10_54_30-Automation - AVB Jira.png

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.
January 20, 2022

Well, that seems incorrect as branches which evaluate to one-and-only-one issue should run in-line, and not asynchronously. 

Would you please post an image of the audit log details as that may show something to explain this behavior?  Thanks!

And if that shows nothing useful, let's try eliminating the branches and substituting with if/else structures, like this with independent if/else components

  • trigger: manual
  • if/else
    • issue field condition: Standard Tabs Type contains Bosch
    • action: edit the field
    • action: re-fetch
  • if/else
    • issue field condition: Standard Tabs Type contains Beko
    • action: edit the field
    • action: re-fetch

One more thing: have you confirmed that custom field ID is what you need for the field?  You may check on the needed smart values for a field using this how-to article: https://support.atlassian.com/cloud-automation/docs/find-the-smart-value-for-a-field/

 

Ryan Wolfe January 20, 2022

@Bill Sheboy I have found that if I pull the "re-Fetch" out of the condition/branch it works.

It looks like this:

  • trigger: manual
  • if/else
    • issue field condition: Standard Tabs Type contains Bosch
    • action: edit the field
  • action: re-fetch
  • if/else
    • issue field condition: Standard Tabs Type contains Beko
    • action: edit the field
  • action: re-fetch

This has been the only way I have gotten it to work.

Thank you for your help though, wouldn't have got on the right path with out it.

Like Bill Sheboy likes this
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.
January 20, 2022

Fascinating, and I am glad you got this to work!

You only need re-fetch if you plan to compare/update the field later in the rule, so you can drop the last re-fetch if you wish.  Each re-fetch call adds potentially several seconds of execution time so use them sparingly.

As there appears to be some timing-dependent things happening in this rule I recommend watching it for a bit to confirm it keeps working.  And then consider marking this question as "answered" so others can benefit when then have a similar need.  Thanks!

Suggest an answer

Log in or Sign up to answer