What trigger the calculated field calculation / how it can be integrated with automation plugins

Léo Dellouve July 10, 2017

Hi,

We would like to have an automated "calculated priority" calculated using JIRA Misc Custom field at issue creation.

We want to use this calculated priority to be used to set some of the fields of the issues (for example the standard priority, target date,...) using an automation plugin.

To pipeline/order the processes, we would like to know

* what trigger the "calculated priority" calculation (issue created JIRA postfunction? Another postfunction?)

* if you know some tricks what can be used to pipeline the jobs (if the calculated customfield raise an event, or if this is possible to set a properties / field of the JIRA issue)

Thanks you,

3 answers

1 accepted

0 votes
Answer accepted
David _old account_
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 10, 2017

Calculated custom fields created by JMCF are updated when the issue is reindexed, which happens when the issue is modified or transitioned. 

However, you will also get a newly calculated value when you access the field using a JMWE (JIRA Misc Workflow Extensions) post function. So you could use JMWE post-functions on your create transition to do the other changes required (using Groovy scripts as value or condition). You might just have to push the post-functions down the list of you get errors. 

To access the Calculated field from a Groovy script, use issue.get(field name). 

David

Léo Dellouve July 13, 2017

Alright, thanks for explanation,

"JMCF are updated when the issue is reindexed, which happens when the issue is modified or transitioned"

"So you could use JMWE post-functions on your create transition to do the other changes required"

 

We tried with JIRA Suite Utilities postfunction. It works in Workflow transition, but not for issue creation (even when this is the last postfunction = after reindexation.

Have you already tested if this work with JMWE at issue creation? (it seems to be the same functionnality, but maybe not the same implementation..)

Capture.PNG

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.
July 13, 2017

Unfortunately, you are right. Recent versions of JIRA caches an invalid null value for all calculated fields during issue creation, instead of waiting for the field to be accessed to calculate its value. This actually has nothing to do with the index (which is only used for searches and the tabular search results view).

There are two possible workarounds:

  1. you use the same formula in the Set Field Value post-function's Groovy value or condition code as you use in your calculated field (instead of accessing the calculated field)
  2. you reload the issue in the Set Field Value post-function's Groovy value or condition code before accessing its calculated field:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue

Issue myIssue = ComponentAccessor.getIssueManager().getIssue(issue.id)

if (myIssue.get("my calculated field") == [...]

The second solution requires that the Set Field Value post-function be placed at the bottom of the list.

Sergio Freire - Xblend
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.
May 15, 2019

Hi @David _old account_ , 

can you please clarify something?

Here you mention that the calculation occurs " when the issue is reindexed, which happens when the issue is modified or transitioned". But in another post (https://community.atlassian.com/t5/Jira-questions/Can-other-field-values-be-changed-when-the-calculation-occur/qaq-p/431990) you mention that the calculation occurs whenever the "view issue screen" is displayed.

Can you please clarify exactly in which situations the calculated field will be refreshed/calculated?

Thank you :)

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 15, 2019

Hi @Sergio Freire - Xblend ,

calculation occurs when:

  • the issue is displayed (issue view)
  • the issue is modified (edit / inline edit)
  • the issue is transitioned

but the index is not updated when the issue is simply displayed.

Sergio Freire - Xblend
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.
May 15, 2019

Thanks @David Fischer . However I've noticed that the calculation is also made in the Issue Search page, right?

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 15, 2019

If you are showing the results in the "Detail View", then yes because it is equivalent to viewing the issue.

Sergio Freire - Xblend
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.
May 15, 2019

No, actually I'm using the standard Issue search page without the details; I'm using the List View mode... and it still calculates it :)

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 15, 2019

Are you using JMCF 2.x, and are you an admin of your Jira instance? In that case, it will indeed recalculate the value for each issue on the result page (so that errors, if any, can be displayed). But note that the search itself will still use the (old) index.

0 votes
Marta Lopez Reyes _UOC_ February 27, 2024

I can't find at the list of fields the calculated fields at automation for Jira? why?

0 votes
Léo Dellouve July 10, 2017

See: https://community.atlassian.com/t5/JIRA-questions/Can-other-field-values-be-changed-when-the-calculation-occur/qaq-p/431990

 

First of all, calculation only occurs when a "view issue" screen is displayed - never during a transition. [...]

Then, calculation occurs during indexing - at which time you cannot modify an issue.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events