Hi,
How can I have a scripted custom field in a sub-task that is taking the value from a field in the parent. I don't mean having the value inherited through a post-function, but always having the fields in the sub-task and the parent in-sync. In my specific example, I have a "Planned Release date" in the parent and I want the sub-tasks for that story to always have this field up-to-date as well.
I tried what was suggested here: https://answers.atlassian.com/questions/284367 but that isn't working for me.
Hi Eugenio,
I attach an example of the code below which shows how to take the value of a Date Field from a parent issue and display it in a Date/Time type script field on the sub task.
The code for this is shown below.
Code:
// Required Imports import com.atlassian.jira.component.ComponentAccessor; // Get the field and its value from the parent issue def parentCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Start Date") def parentCFVal = issue.parentObject.getCustomFieldValue(parentCF) as Date; // Check if the issue is a subtask and if so return a value if (issue.issueTypeObject.name == "Sub-task") { // Get the value as a timestamp required by the date range picker def startDate = new Date(parentCFVal.time); return startDate }
Please note if you want the returned value to be formatted you can use Java Simple Date format if you change the fields template and searcher to be free text and use code similar to the example code below.
// Required Imports import com.atlassian.jira.component.ComponentAccessor; import java.text.SimpleDateFormat; // Get the field and its value from the parent issue def parentCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Start Date") def parentCFVal = issue.parentObject.getCustomFieldValue(parentCF) as Date // Check if the issue is a subtask and if so return a value if (issue.issueTypeObject.name == "Sub-task"){ // Get the value as fomrated as Day Day Month Month Month Year Year return parentCFVal.format("dd/MMM/YY") }
I hope this helps
Kristian
better to use issue.isSubTask() than check the issue type name really, also check that before reading the parentObject, otherwise you will get a NullPointerException.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is perfect. With your suggestion (plus Jamie's suggestion) I got it working perfectly.
Thank you!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Glad we were able to help Eugenio.
Kristian
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.