I want to calculate different fields by the selected values of an issue. But some of the calculated fields depend on other calculated fields, so I'm faced with a very complex set of calculations.
To stay with the core problem I will describe a simplified showcase:
Because all calculations are very complex, I don't want to repeat the intermediate calculation steps in each of the descendant KPIs.
So my questions are:
I would appreciate your experiences, recommendation and alternative solution patterns.
Thank you very much.
Whilst you technically can use a scripted field as one of the inputs to another scripted field, you'll find it does not work.
You can't guarantee what order scripted fields are going to be calculated in, so you could easily end up with the wrong answer in the dependent one.
Imagine you create fields:
Weekend: a scripted field that looks at the due date and holds 0 for a weekday, 2 when it's a Saturday and 1 when it's Sunday.
Working due date: a scripted date field that is (due date + weekend day value)
Let's say someone puts in a due-date that lands on a Saturday. Working due date should be Monday, but sometimes its going to show Saturday because the calculation of the weekend number happens after the working due date. You can't control that.
You might be better off changing your first layer of scripted fields into custom fields, and populating them in a listener that picks up create and edit events (don't put them on the create or edit screens - that will stop people changing them). Then your scripted fields that use their values as inputs will work fine, because custom fields are set before the scripted fields start to execute.
Thank you for answer.
You recommend listeners and listening for update events. We already have some listeners for update events. To propagate all KPIs do you recommend a new listener for each KPI or do you recommend integrating all KPI calculations into an existing update listener?
My question is also about possible race conditions as well: I'm affraid that if different listeners populate various fields at the same time and dispatch the change event so I will get lost in a hell of events.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.