inherit custom field values from parent to subtasks

Hi,

I created a custom field in Jira which is "Customer ID" and I would like if a parent task has this field, all subtask inherit the value of this custom field automatically and no one allowed to change custom field value of it in subtasks.

Could you please kindly tell me how can I do it ?

Best Regards,

4 answers

This widget could not be displayed.
Mahesh S Community Champion Sep 28, 2016

Introduce a 'scripted field' using script runner plugin. Hide it from the screens. Using the scripted field, update the custom field value in the subtasks.

OR

Introduce a 'scripted field' using script runner plugin. Set it for the subtasks alone using field conf or screen or set field context. Get the custom field value form parent and just display in the subtasks. 

 

 

This widget could not be displayed.

Hi Amir,

as Mahesh mention you can use Script runner addon.

  1. add 'Custom script post-function' to your workflow on Create transition
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.*;
import com.atlassian.jira.issue.util.IssueChangeHolder;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;
def IssueManager issueManager = ComponentAccessor.getIssueManager();
def CustomFieldManager customManager = ComponentAccessor.getCustomFieldManager();
def IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
//get and update value of my customField CRM ID
try {
    if (issue.getIssueType().isSubTask()) {
        def String crmID = issue.getParentObject().getCustomFieldValue(customManager.getCustomFieldObjectByName('CRM ID'));
  		customManager.getCustomFieldObjectByName('CRM ID').updateValue(null, issue, new ModifiedValue(null, crmID as Double), changeHolder);
    }
} catch (Exception ex) {
  log.error(ex.getMessage());
}

2. move your post function till the end of list, at least after Issue Created.

3. publish your update workflow

Happy inheriting smile

Regards,

Petr

Mahesh S Community Champion Sep 28, 2016

Hi Peter, my suggested solution is with scripted field and yours is with scripted post function. Glad to see your script here. However, once we add this scripted post function, subtask's custom field will get updated from the parent  when it make a transition.

But, how will the existing issues in different states will behave in this manner, when we do not make any state changes?

Existing issue will not be affected. You have to do one-time-update with another script...

Mahesh S Community Champion Sep 28, 2016

Exactly! But, I believe Amir needs it for all issues both newly creating ones and existing ones.

This widget could not be displayed.

You can create a further custom field "Customer ID Sub" which should be configured only on the view screen of you sub task. (In the view screen it can be configured as read only).
Use the plugin Workflow Essentials and put the post function "Copy field value from parent to sub-task " into the create transition of you sub task. As soon the sub task is created the post function will copy the field from "Customer ID" to "Customer ID Sub". 

Mahesh S Community Champion Sep 28, 2016

True it works using the post function when we create or do a transition. But how will it update when you make changes in the parent dynamically and no state changes happen in subtasks?

This widget could not be displayed.

The Field Teller plugin allows you to configure fields to be displayed in the subtask. No value copying is done and values cannot be changed from the subtask. It's not a free plugin, but it is not really expensive either.

Hope it helps.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

162 views 1 3
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you