Calculate sum of custom number field from all subtasks with an Event-based Action

Estelle Decanis
Contributor
May 4, 2022

Hi,

I want to use an Event-based Action to sum a number field.

More precisely:

The customfield_10238 is present in all subtasks of a story, and I want to display the sum in a field of the story (customfield_10231).

I found some conversations about this but I can't apply to my situation. Could any of you help me?

 

Thanks in advance

 

4 answers

1 accepted

3 votes
Answer accepted
David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 4, 2022

Hi @Estelle Decanis ,

it's actually not that easy. You can use an event-based action that listens to changes to the customfield_10238 field on issues of type sub-task. Then you can use a Set Issue Fields post-function on that action to set the parent issue's customfield_10231 to the sum of customfield_10238 on all sub-tasks. You have to select "Parent of the current sub-task" as the Target Issue(s), and for the value a script like:

{{ targetIssue | subtasks("customfield_10238") | sum("fields.customfield_10238") }}

However, this will only work if customfield_10238 is present on all sub-tasks, otherwise it'll return NaN.

Another difficulty is when you add or remove a sub-task. You also need to recalculate the parent issue's customfield_10231 value.

Estelle Decanis
Contributor
May 4, 2022

Great! It works. Thank you very much @David Fischer 

Estelle Decanis
Contributor
May 4, 2022

@David Fischerone last question.

The customfield_10238 calculation should be triggered when there is a logtime entered. So I put the trigger on the update of the Time spent field.
Unfortunately this does not trigger the action. What is the error?

 

2022-05-04_20h56_37.png

 

In the meantime I added Original estimate (and made a voluntary modification) to make it work

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 4, 2022

Because Jira doesn't trigger an event when that field is updated.

Have you tried listening to the Work Log Created event?

Like Estelle Decanis likes this
Estelle Decanis
Contributor
May 4, 2022

ok, I understand better.

No I didn't try because the title of the subtasks is explicit and therefore they don't fill the work log

Estelle Decanis
Contributor
May 4, 2022

I haven't thought about it, the work log is not necessarily the description of the logtime. Indeed as it creates a line it should work. But I have to create a similar action if the line is updated, and another one if the line is deleted.

Thank you very much for your information, it was very useful

Estelle Decanis
Contributor
May 5, 2022

@David FischerI created new tickets and made a new test, but it does not work anymore.

The 1st logtime (7h) is displayed in the customfield_10238, but is not displayed in the Sum (customfield_10231) of the parent ticket. The Sum remains at 0.
I add a logtime (1h) on the same subtask, and the Sum displays 7, but not 8.

 

(Customfield_10238 and customfield_10231 are Number fields with the default value of 0). What is my mistake please?

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 5, 2022

What's customfield_10238? In the previous screenshot you mentioned Time Spent and Orginal Estimate, so I'm a little confused...

Estelle Decanis
Contributor
May 6, 2022

Sorry. I resume :

2022-05-06_09h16_35.png

The customfield_10238 is filled with 3 actions :

  • if work log is created :

2022-05-06_09h20_22.png

  • if work log is updated :

the same with the trigger 'Work Log Updated'

 

  • if work log is deleted :

the same with the trigger 'Work Log Deleted'

Estelle Decanis
Contributor
May 6, 2022

and for the customfield_10231

2022-05-06_09h18_14.png

 

I did this :
2022-05-06_09h33_11.png

 

And the same with the trigger 'Work Log Updated'

and with the trigger 'Work Log Deleted'

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 6, 2022

Since the second event-based action depends on the first one, you should use a different trigger. You should listen to changes to customfield_10238 instead of work log changes in the second action.

Like Estelle Decanis likes this
Estelle Decanis
Contributor
May 6, 2022

Yes ! Thank you very much! Yes, that was my old setting and I didn't remember changing it.

Thanks again for your help David

 

So for the customfield_10231 :

2022-05-06_10h45_42.png

 

The trigger 'Tempo (h)' is customfield_10238

Estelle Decanis
Contributor
June 3, 2022

Hi @David Fischer ,

I get this error :

Error message : Expected a Number but got: NaN

I don't understand. It's always the same number field. And from memory there was no change in the settings. What can cause the error ?

Regards,
Estelle

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 3, 2022

Hi @Estelle Decanis ,

it might be happening when at least on sub-task doesn't have a value for that custom field.

Estelle Decanis
Contributor
June 6, 2022

Indeed the old issues did not take into account the change of parameter setting (set to 0 by default). Thanks for your help @David Fischer 

0 votes
Hannes Obweger - JXL for Jira
Atlassian Partner
May 4, 2022

Hi @Estelle Decanis

for a completely different direction - is it a hard requirement for you to put your sub-task calculations into a field at the parent issue?

I'm asking because there's a number of apps in the Atlassian Marketplace that would perform such calculations "on the fly", based on a given set or hierarchy of issues. The advantage of such a solution is that it is often far more lightweight and flexible, as you don't need any kind of automation or scripting. The disadvantage is that you can't usually use the result in other Jira views or JQL.

If this is a direction that could work for you, I'd be more than happy to share how this works in the app that my team is working on, JXL for Jira.

Best,

Hannes | https://jxl.app

Estelle Decanis
Contributor
May 4, 2022

Thank you for your feedback @Hannes Obweger - JXL for Jira

On each subtask the collaborators enter time. And I have to display the total time of all these subtasks on the parent ticket. Indeed in a field, in order to show it in the dashboards.


There are certainly points to study on other issues

0 votes
Estelle Decanis
Contributor
May 4, 2022

Hi @David Fischer You have answered a question of this type, have you got an idea ?

0 votes
Mark Segall
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 4, 2022

Hi @Estelle Decanis 

You can accomplish this through automation (Note - This assumes your custom fields are numeric fields):

  • TRIGGER: Field Value Changed
  • CONDITION: Issue Type = Sub-Task
  • BRANCH: Parent
    • ACTION: Edit Issue (select your custom field 10231) and use the following:
      • {{issue.subtasks.customfield_10238.sum}}
Estelle Decanis
Contributor
May 4, 2022

Thanks for your help @Mark Segall . Indeed I had done the automation.

I want to take the time spent of the ticket, transform it in hour and make a sum in the parent ticket. It's easier to work directly with Event-based Action.

And with automation, the trigger corresponding to the update of the time spent does not work. So I would really prefer to use an event-based action

Mark Segall
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 4, 2022

Understood - I'll defer to other community members.  Good luck

Estelle Decanis
Contributor
May 4, 2022

ok thank you

Suggest an answer

Log in or Sign up to answer