Howto set multiple scripted fields with single script during issue - view

I’ve created a single script to calculate some time-to-SLA parameters ( - time to resolve, time to respond, Time to fix&Patch - ).  Goal is to display accurate time-to-SLA values based on current date-time.

Currently for each SLA parameter a  (script runner) scripted field has been created and linked with the script. As I’m already displaying 4 time-to-SLA parameters ( - and hence 4 scripted fields are linking to same script - ) I was wondering what’s the (best) approach to set multiple fields in single script ( - when ticket is viewed - )

I’ve been playing with a Script Runner Listener which I can use to set value of multiple fields in single script but data is not accurate as listener is only triggered during Issue Create, Issue Update, .. events.  The time-to-sla parameters should be (re)calculated and set each time ticket is displayed. Tx!

1 answer

Hi Christof,

I think I understand what you're trying to do. However, I am slightly confused. When you say each SLA parameter scripted field is "linked" to the single script that does the calculation, what is meant by this? How are they linked?

The core advantage of using script fields is that you can just place the script inside them to return a value, without using an outside method to set them (like a listener).

Why not just split up the single script into four different scripts, and place that code into their respective script fields?

For example:

Time to Resolve field

//place code in script field that does the Resolve calculation
//return the value

Time to Respond field

//place code in script field that does the Respond calculation
//return the value

And so on.

Yes, you'll have code repetition. But, you'll solve the problem of having outdated values. Script Fields will automatically recalculate their value whenever the issue is loaded.

Tx for your feedback! Correct – this is how I’ve got it implemented at the moment. 5 scripted fields have been created and each of them linked to their own script. Unfortunately there is a lot of code repetition and hence my question if there is a way to tweak this.

The reason to optimize this is twofold;

  • Because there is a lot of code repetition I have to maintain ‘same’ source-code multiple time. If I want to add minor changes or fix a bug, I have to update 5 different scripts.
  • Performance issue – now the script is executed 5 times ( - 1 time per scripted field - ) and as we’re already facing some performance issues with our Jira instance it would be great if I can reduce this.  

Is there any possibility to set multiple scripted fields via 1 single field ( - or this doesn’t exist yet - ) ?        

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 13, 2019 in Marketplace Apps

Marketplace Spotlight: Marketing apps for Confluence to keep your teams working on the same page


254 views 0 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you