inherit custom field values from parent to subtasks

Amir Kalhori September 28, 2016

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

0 votes
Caner Arda December 15, 2016

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.

0 votes
codecentric AG September 28, 2016

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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 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?

0 votes
Pecan September 28, 2016

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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 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?

Pecan September 28, 2016

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

Like Alessandr likes this
Mahesh S
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 28, 2016

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

0 votes
Mahesh S
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 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. 

 

 

Suggest an answer

Log in or Sign up to answer