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.
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
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.