Hi,
I am new to ScriptRunner and Jira Software. Below is the details of the issue:
We have 2 scripted fields (ex: SF1 and SF2). The SF1 is a scripted number field whicg add's the number selected from 3 custom fields (CF1, CF2, CF3)
so SF1 = CF1+CF2+CF3. I am able to get the correct output for SF1.
The SF2 is also a Scripted number filed which should take the output from SF1 and divide with another Custom field (CF4) and show the output on the SF2
Ex: SF2 = SF1 + CF4
The first part of the script (SF1 output) is working fine. But i am unable to find a method to pass the SF1 output as input for SF2.
Could anyone help me with any function on how to fetch the value from Scripted field and add to custom field?
Thanks in advance for help!
I'll nick Nic's reply from https://community.atlassian.com/t5/Marketplace-Apps-Integrations/Possible-to-use-a-scriptrunner-script-field-value-in-another/qaq-p/681430
The easiest way to think of this is that "a scripted field value is calculated and stored during the indexing of the issue". If you have more than one calculation happening during that indexing, then it's effectively random as to the order in which that happens. Which means that sometimes, a calculation based on another scripted field might take the old value, or the new one, or, in some cases, even a random number! The fields are recalculated even if their input data has not changed.
So, don't read scripted fields from the current issue in other scripted fields. It won't work (reliably). It's fine to read them from other issues, but never the current one.
It is far more reliable and easier to replicate your steps from SF1 inside SF2. The SF1's value will not be reliable "source". If SF1 changes, SF2 is likely to have incorrect value, and vice versa.
As a rule of a thumb, given how scripted fields work with indexes (and value "storage"), it's best to always avoid trying to read another scripted field's value.
Hi, @Prasad A
There is no secret oh hidden logic. Just take value from custom field SF1 and divide it with CF4.
There is one small, not obvious problem - values in issues appear only when they (issues) are opened by user, for example. If issue wasn't opened, values in customfields == null.
Of course, you can use workaround with sheduled reindexing of issues, it's not standart way to solve such problems, but it will help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No, I'm afraid that is not a valid approach. It is a mistake people inexperienced with Scriptrunner make a lot, but it's really not obvious, and whilst our docs mention it, most people won't try to to it, so we've not put it in a huge red box.
You should never read the value of a scripted field as an input to another. Especially during the same update action.
Where the question is
the calculation for SF2 is likely to fail. It needs to be rewritten as
(Assuming Cf1-4 are all content-containing custom fields, not scripted fields)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.