Forums

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

Trying to use a Scripted Field value in another Scripted Field

David Laperle
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.
January 9, 2019

Hi dear Atlassian community,  been a long time JIRA admin, but we recently acquired ScriptRunner for jira for a new project we're working on. 

On a that project, we'll have a few scripted field which are based on standard custom field. 

In one of those scenarios, we have a the following setup: 

- Task A

-- Scripted Field A : Value should be value of Scripted Field B

- SubTask B (Under TaskA)

-- Scripted Field B : Sum of CustomField1 and CustomField2

I basically want to show the value of scripted field of a sub-task on the parent task.

I could done the same logic on Scripted Field A, but that would duplicate my code if ever i need to do modification to the logic of Scripted Field B, i'd have 2 fields to modify, which i'm trying to avoid.

So in theory, it seems ScriptRunner supports that, but when i'm trying this, it seems like the first time i hit Preview, it doesn't work, but the second time it works. 

By working here, i mean i'm able to retrieve the value of Scripted Field B from Task A.

This works in debug mode, since i can hit preview multiples times and see the result, but in the real life scenario, when i refresh Task A, the value is empty since it tries only once. 

So i'm guessing this is enough context, but i'm wondering if there's something specific that i need to do in order to do that type of flow using ScriptRunner Scripted Fields.

PS.: Also tried to turn off caching like specified in the Scripted Field documentation.

1 answer

0 votes
Ivan Tovbin
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.
January 9, 2019

Hi David,

Have you tried to re-use your scripted field A in your sub-task, and simply modify the code to check for current issue type. If it's a standard issuetype, then grab your custom field values from it, if not, then grab them from parent. I think it'll take a single line of code to modify it:

def issue = (issue.isSubtask()) ? issue.getParentObject() : issue
David Laperle
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.
January 9, 2019

Hi Ivan, first thanks for your answer.

Doing so won't I get the same problem where i'm trying to fetch data from another Scripted Field?

So wether i'm fetching Scripted Field B from Task A or Scripted Field A from SubTask B i'm in the same gray area where getting the scripted value could lead to caching/out-of-sync issues?

Ivan Tovbin
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.
January 9, 2019

No, not really. Basically what you'll do is fetch the value from the issue itself if it's NOT a subtask. If it is, then it first finds its parent, and then fetches the value from there.

Incidentally, in your setup, is there always ONE subtask per parent issue?

Hope this helps.

Suggest an answer

Log in or Sign up to answer