When Sub-Tasks are created from a Story, I would like the parent Story's custom field value to be copied to the Sub-Task's custom field value. For example: I have a field named "Client" and I want the value to appear within the Sub-Task's "Client" field after the Sub-Task is created.
I am not interested in a paid add-on for JIRA and would like to use Script Runner instead.
I have tried to test my script below using the console, but am getting errors related to "issue" and "transientVars" not being understood.
Thank you for your help in advance!
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 com.atlassian.jira.issue.MutableIssue CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager() CustomField customField_name = customFieldManager.getCustomFieldObjectByName('Client') def parentMyFieldValue = transientVars["issue"].getCustomFieldValue(customField_name) issue.setCustomFieldValue(customField_name, parentMyFieldValue)
Hi,
If you run the script in script console, you have to use an issue as an example. Its not there in the context when you run it from the console.
For testing purposes, use below line in the code.
issue = ComponentManager.getInstance().getIssueManager().getIssueObject("TEST-1234")
If you put the script in post function, you might not get error for this.
Option will also be to do use the JIRA Suite Utilities Plugin, its free.
https://marketplace.atlassian.com/plugins/com.googlecode.jira-suite-utilities
The plugin provides the post-function to copy value from other field, from parent to sub-task. You can add this post-function in the create transition for the sub-task.
Vijay
As Vijay says... if you test this as a workflow action it should work.
Note that in this scenario, issue refers to the new issue being created, and transientVars["issue"] refers to the parent or source issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you! I decided to try out the JIRA Suite Utilities Plugin and it did just what I needed. I created a post function for each field that I wanted to copy from the parent using the "Copy Value From Other Field" function.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
JSU will not do this in Jira Cloud for the "Accounts" field from Tempo. The JSU post-function does not include the ability to run the post-function as the transitioning user vs the addon-user.
Hoping that will get fixed soon!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Alan
We're still working on getting all the features on Server to Cloud. However, as we have to basically re-create the App on a different platform, this is taking a while.
Stay tuned for updates!
Benjamin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is this answer still correct for JIRA 7 API? I had to change to use ComponentAccessor as there is no longer a getCustomFieldManager() in ComponentManager. Also, this line statement throws an error
def parentMyFieldValue = transientVars["issue"].getCustomFieldValue(cfParent)
could not find java.lang.Object#getCustomFieldValue. Do I need to cast transientVars["issue"] to something more appropriate?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What is the context here, are you using one of the built-in scripts, or is this completely custom?
Yes, that API has changed, you can read what you need to do here: https://scriptrunner.adaptavist.com/latest/jira/releases/UpgradingToJira7.html
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for pointing me to the JIRA 7 page.
I initially tried to drop in the code from above as I have the same need as this question. I got an error when trying to use transientVars so I poked around and came up with the code below. It works but I'm not sure if it is the best way now so if you have any critiques I'll take them.
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.IssueManager import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.util.DefaultIssueChangeHolder import com.atlassian.jira.issue.ModifiedValue def field = ComponentAccessor.getCustomFieldManager().getCustomFieldObject('customfield_10603') def parentMyFieldValue = issue.parentObject.getCustomFieldValue(field) def changeHolder = new DefaultIssueChangeHolder(); field.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(field), parentMyFieldValue),changeHolder);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Paul, do you have any idea to apply above code for fix version copy ?
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.