Hi
I want to get the parent task field value through Script runner Behavior. But the acquisition method seems to be different from the Post function.
Thanks for your help.
Best Regards.
@jack ma
i tried this in a test behaviour and both is working. I hope this is it what you are searching for:
Kind regards.
Hi@Fabian Laqua
I really appreciate your help.
After I used your code to execute it, an error was reported. The error message is as follows:
Best regards.
Hi @jack ma
If you want to pass a value from an Issue to a Sub-Task, you could try something like this:-
import com.atlassian.jira.component.ComponentAccessorimport com.onresolve.jira.groovy.user.FieldBehavioursimport groovy.transform.BaseScriptdef cost = getFieldByName("Cost")def customFieldManager = ComponentAccessor.customFieldManagerdef costUpdate = customFieldManager.getCustomFieldObjectsByName("Cost")[0]@BaseScript FieldBehaviours behavioursif (underlyingIssue != null && underlyingIssue.isSubTask()) { def parent = underlyingIssue.parentObject cost.setFormValue(parent.getCustomFieldValue(costUpdate))}
Please note, this sample code is not 100% exact to your environment. Hence, you will need to make the required modifications.
The code will not work on the Sub-Task's Create screen. It will only trigger once the Sub-Task is created and the Edit Screen is used.
Alternatively, if you want to see the result immediately after the Sub-Task has been created, it would be better to use the Scripted Field.
I hope this helps to answer your question.
Thank you and Kind Regards,Ram
Dear @jack ma ,
what scriptrunner version do you use?
In an behaviour, you get the current issue with the issueContext
Plz try, if it is empty or not?
This works too (Full code, no import needed in a behaviour, initialiser!):
log.warn("DEBUG now:")log.warn(issueContext)log.warn(getIssueContext())
Source: How to get current issue object in Behaviour ? (atlassian.com)
How i did my example:
1. Created a behaviour
2. mapped it to my jira project and subtask
3. created an Initialiser
4. wrote my example.
If it doesn`t work, try out getFieldById(<Issue key field>) and then you can use the Issuemanager to get the issue like in my example above.
The script version I use is 6.3.0-p5 Jira version is v8.0.2
I’m on the issue creation interface, and I haven’t finished creating it yet, I want to get the value of the parent task field when creating a child task. so I can’t use the getFieldById() method to get the value of issue key.
Thank you and Best Regards.
Hi@Ram Kumar Aravindakshan _Adaptavist_
I have tried your method, but the result of the underlyingIssue is null. The scriptrunner version I use is 6.3.0-p5.
Thank you and Best Regards
The ScriptRunner version you are using is pretty outdated, and there have been many bug fixes since that release.
If you are using Jira 8.0 and above, you can upgrade the ScriptRunner plugin to the latest release, i.e. 6.32.0.
The test I have done is using the latest release of ScriptRunner.
Thank you and Kind Regards,
Ram
It looks like you're new here. Sign in or register to get started.