Update the Custom Date field in Sub-Task if the Parent Custom Date Field is Updated

Hi,
I am creating a sub-task from the script-Post Function that creates a sub-task on the transition.

am copying all the fields from parent task to sub-task

When I update a Custom Date Field in the Parent task, It should get carried to the subtask as well.

It was resolved

and I want to extend the functionality to the linked issues if that's possible.

 

2 answers

This widget could not be displayed.
Tayyab Bashir Community Champion Oct 29, 2017

So your main question is regarding updating linked issues if the customfield is updated.

You would need to write a script listener on issue updated events for that. 
Which would pick up changes on the customfield and propagate them onto the linked issues.

But issue links don't have relationship of parent/child. 
So if you update the customfield from either side of the issue link, the other issue would be updated. 
Or you would have to make a logic that suits your need and code it with script listener. 

This widget could not be displayed.

Hi Bunny, 

In the case of the subtasks you will need a Custom Script Listener that will listen for issue updated events and you script will look like 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

def issue = event.issue as MutableIssue
def change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "First DateTime"}
if (!change) {
//the update was not caused by a change to First DateTime field so do nothing
return
}

def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("First DateTime")
def parentValue = issue.getCustomFieldValue(cf)

// update the cf value for all the subtasks
issue.subTaskObjects?.each {
updateCFValue(it, cf, parentValue)
}

// update the cf value for all the linked issues
getOutwardLinkedIssues(issue)?.each {
updateCFValue(it, cf, parentValue)
}

def updateCFValue(MutableIssue issue, CustomField cf, def newValue) {
def changeHolder = new DefaultIssueChangeHolder()
cf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cf), newValue),changeHolder)
log.debug "Value for custom field ${cf.name} for issue ${issue.key} updated to ${newValue}"
}

def getOutwardLinkedIssues(MutableIssue issue) {
ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.id)?.collect {it.destinationObject}
}

So what this script does is, in an issue updated event, it checks if the field that go updated is the First DateTime and if it is then it goes through the subtasks and the links of that issue (if there are any) and update the value of that custom field. 

regards, Thanos

The code gives an error, updateCFValue() methof is not found Thanos, Can you please help me out with the error

Thankyou for all your support Thanos.

Hi Thanos,

I would you like to use your script for update the Due Date field in Sub-Task if the Parent Due Date Field is Updated using a script listener, BUT your code gives the error below ...Error.png

Could you suggest me the correction with the modification for use the Due Date field?

Thanks in advance,

Francesco

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted yesterday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

70 views 1 0
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