Possible to use a scriptrunner script field value in another script field? Edited

Hello,

 

Right now I have a script field generating a numeric value based on severity and priority. This number is being used in some reporting outside of Jira and for force ranking.

I have another field that I would like to use the numeric script field value to calculate a due date. 

Is it possible to get the value from another script field? When I try the following the script dumps out silently.

 

This code trying to pull from the other script field:

import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import org.apache.log4j.Logger
import org.apache.log4j.Level

def log = Logger.getLogger("com.acme.CreateSubtask")
log.setLevel(Level.DEBUG)


//Get CIF Value
log.debug "Getting CIF";
def cCIF = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_12708");
def CIF = issue.getCustomFieldValue(cCIF) as Integer;
log.debug "CIF is $CIF";

 

Results in this:

2017-11-30 14:38:19,578 DEBUG [acme.CreateSubtask]: Getting CIF

 

At the moment I have it working by including the first script field's logic in the second script field but it will lead to the codebases being likely to wander.

Alternatively could I have the first script field also set a regular custom field as it runs? I did not have any luck with that.

Thank you.

1 answer

This widget could not be displayed.

You can, but you have to be careful not to go into a loop.

You can only rely on the value of a scripted field in another script if the current process is not going to update the value. 

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.

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Published yesterday in Marketplace Apps

The 7 hacks of highly successful automation

...there's anything I've learnt from working, it's that people are lazy! No offense to anyone reading this, but it's true and we can all admit it. The easier you make something for someone, the more...

141 views 0 9
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