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.
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.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
def cost = getFieldByName("Cost")
def customFieldManager = ComponentAccessor.customFieldManager
def costUpdate = customFieldManager.getCustomFieldObjectsByName("Cost")[0]
@BaseScript FieldBehaviours behaviours
if (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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @jack ma
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
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi@Fabian Laqua
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear @jack ma
now i understand your problem. There isnt a sub-issue yet. So you cannot cast to mutableIssue.
Why do you need the parent issue in the create mask?
Is there a special field you need to display or process?
If you need to display that data, then you can use a post function in the sub-taks-create transition to get that field.
Or do you need to recalculate something with this field in the create mask?
And that underlying wont work either in the create transition. I tried it out. But if you that sub-issue in edit the "underlying" works.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This works only in the create transition:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.onresolve.jira.groovy.user.FormField
IssueManager im = ComponentAccessor.getIssueManager();
FormField formfieldparent = getFieldById("parentIssueId")
Long parentIssueId = formfieldparent.getFormValue() as Long
log.warn("TEST formfieldparent: " + formfieldparent)
log.warn("TEST parentIssueId: " + parentIssueId)
MutableIssue issue = im.getIssueObject(parentIssueId);
log.warn("FINISHED: " + issue)
With that parentIssueId, you can get the parent issue with the issueManager i posted at first.
Kind regards.
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.