How does a ScriptRunner scripted field actually work?

Adam Holloway August 10, 2022

I'm partly trying to better understand how Jira works but also trying to solve a charting problem involving historical data that relies on data from a scripted (numeric) field.

So I have a scripted field called 'Score'. Score does a simple numeric calculation that populates a custom script field that I created (Number Searcher type). The field only appears on a single issue type but across all projects. It works by creating a score value based on two other string fields. It returns a computation when either of those two fields are changed on any ticket that also has the Score scripted field.

So how does ScriptRunner know when to run the script? The Groovy script itself is fairly simple, just a 'If' statement that gets both of the qualitative string fields and compares them to a list and then calculates a score based on those results.  What does it write to the Jira database? Does it just update the Score field variable (or column) irrespective of time for the ticket entry in the database? If so, how do I create a scoring history per se? In other words, how do I time stamp those scoring changes?

As it stands now, I can chart(in eazyBI) the change of scoring but the effective date of any score change is the ticket creation date, regardless of how many historical measures I import and analyze. For example, the 'change' measure only shows aggregated sums on the days when tickets were created and not actually changed. 

Any insight would be appreciated. Thanks.

2 answers

1 vote
Janis Plume _eazyBI_
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.
August 10, 2022

Hi @Adam Holloway 

 

One comment about capturing the history of the scripted field value in eazyBI. It does not happen automatically; you must build the value change list yourself. Please, check an example of how to do that: https://docs.eazybi.com/eazybi/data-import/data-from-jira-apps/jira-calculated-and-scripted-custom-fields

The example about Original estimated hours history could be the closest to your use case.

Kindly,

Janis, eazyBI support

Adam Holloway August 12, 2022

Thanks @Janis Plume _eazyBI_

What you describe is part of the problem/solution. The custom field script doesn't write to the ticket history - it just updates the value so it makes sense that the time reference on import into eazyBI,  in this situation, is always the ticket creation date, regardless if that value is calculated x 1000 times. Just wondering if there isn't a more elegant way to write that custom field change to the ticket history than what is described in those examples. Maybe not, I  just don't know enough about Groovy/java. I'll have another look.

1 vote
Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 10, 2022

Hello @Adam Holloway ,

to my understanding, the value is calculated (and stored) each time you are viewing the issue (as requesting the view issue screen).

I created a scripted field (randomized number, so I get a new one each reload).

Then I created a filter and added the field in the columns. If i click "Search" multiple times, nothing happens. If I refresh the issue, then click "Search" again, a new value appears for the scripted field.

Hope that helps.

Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 10, 2022

In addition : this is confirmed by the documentation

"The value for a field is calculated at the time an issue is displayed or updated"

I should have started by looking at it.

Suggest an answer

Log in or Sign up to answer