Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Jira Automation not triggered when scripted field changes

Craig Goulden
Contributor
January 31, 2023

I have a scripted field (created in ScriptRunner) called Total Completed Story Points on Epics that rolls up the Story Points for all the child Stories that are in a Completed Status.

I added a Jira Automation rule to update another custom field when the Total Completed Story Points field value changes.

The rule is never triggered, even though when I complete a Story the parent Epic has the Total Completed Story Points field value updated.

I'm guessing that Jira Automation only triggers when a specified field is manually edited, and not when the value of the field is changed by a script. Is this the case? Is there some way to trigger Jira Automation on a field when the value is changed by a ScriptRunner script?

2 answers

1 accepted

0 votes
Answer accepted
Nic Brough -Adaptavist-
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.
February 14, 2023

You won't be able to do this.  Scripted fields do not change values in the same way that other custom fields do, Jira is not actually directly aware that they change.  So Automation, Listeners and the issue history don't get anything when they do.

You will need to look at the script behind the field.  What does that do?  You'll need your automation or listener to pick up something that would make the calculated value change.

If, for example, your script says "scripted field = field X + field Y", then your automation or listener should be looking for changes of X or Y.

Craig Goulden
Contributor
February 14, 2023

Thanks for the info, @Nic Brough -Adaptavist- 

The custom field adds up the Story Points fields for all the child Stories under the Epic. So this value changes when a child Story is Resolved or Reopened.

Total Completed Story Points script.png

 

Craig Goulden
Contributor
February 14, 2023

I tried putting a listener on the Issue Resolved and Issue Reopened events so I can catch the Stories changing state, and then update the parent Epic's custom field, but this listener also doesn't trigger.

Any ideas what I could be doing wrong?

Listener on Issue Resolved and Reopened events.png

Nic Brough -Adaptavist-
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.
February 15, 2023

Ah, I think I have found it.

Your script appears to be for adding up story points from links on to a field on the current issue.

But not just adding - accumulating.  When issue-123 is resolved, add the story points to Epic-456's running total. i.e. total completed story points += linked sp

Nothing wrong with that, but it's not going to work with a scripted field.  The value of the scripted field is being recalculated by the script currently running.  So there's no value in it at the beginning of the script, which Jira has to assume means "0".

You could do it in a scripted field, by parsing what you need out of all the issue histories, but that's a lot of code and a lot of load.

I would delete the scripted field, and start again with a custom number field.  Do not put that on any create/edit/transition screens so the humans can't interfere with it, and run the same calculation code you have for the scripted field, adding the "write to custom field" code you'll need.

Craig Goulden
Contributor
February 23, 2023

Hi @Nic Brough -Adaptavist- 

Not quite, I think. Ignore the listener code. I gave up on this because I couldn't get it to trigger. The scripted field script actually runs through each child story to sum the Story Points from zero every execution, so it's not cumulative.

I'm not sure if it is the right thing to do, but I got it to work by just adding code to the Total Story Points scripted field to also update the Actual Effort custom field. So I'm updating 2 fields with one scripted field. Doesn't feel right to me, but it works.

I'm not sure what triggers a custom field to calculate but, strangely, I need to refresh the tab displaying the parent Epic twice to see the updated Actual Effort value.

Here's the Total Completed Story Points script:

Script for Total Completed Story Points field and Actual Effort field.png

Does this look alright? Any suggestions?

Nic Brough -Adaptavist-
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.
February 24, 2023

It looks right to me.

You will always have to refresh a page to pick up that a field has been changed outside the current screen.

Like Craig Goulden likes this
Craig Goulden
Contributor
February 26, 2023

Thanks Nic.

I take your expert opinion as validation :-)

0 votes
Kian Stack Mumo Systems
Community Champion
February 13, 2023

@Craig Goulden

Are the changes to the scripted field being shown in the issue history of the ticket? Either way, it looks like this may be a known issue!

 

Thanks,

Kian

Craig Goulden
Contributor
February 13, 2023

Yeah, that looks like the problem to me. The scripted field change in the parent doesn't appear in the history.

I'm working with Adaptavist.

The first suggestion was to avoid Jira Automation and just use a listener on the scripted field. This didn't work for what I'm guessing is the same reason; the listener isn't triggered by the scripted field value change.

The next suggestion is to create a listener on the child story, and in the listener update the parent epic.

I'm still working on getting this to work.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.20.10
TAGS
AUG Leaders

Atlassian Community Events