Hi,
Scenario: My team sends a Tempo extract of hours logged on tickets to finance team once a month. Before we send the report- we need to ensure all the ticket fields are flagged properly. A major issue we encounter is when subtasks custom fields become out of sync from their parent tasks. I have the subtasks inheriting parent custom fields on create- however when someone updates a field on the parent and forgets to update the children they can become out of sync.
Question: Can I get help writing a script I can run on the Script Runner console once a month before I pull the report to ensure all the parent and child tickets in the project are in sync? Is this feasible or is there a better solution? Thanks so much
A better solution would be writing a script listener that fires on issueUpdated event and fills in the child custom fields accordingly.
https://scriptrunner.adaptavist.com/latest/jira/listeners.html#_custom_listeners
Hi,
I have the same problem and I have try a code but nothing happend
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
def change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "Labels"}
if (change) {
log.debug "Value changed from ${change.oldstring} to ${change.newstring}"
// your actions if the field has changed
def subtasks = event.issue.getSubTaskObjects()
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Labels")
if (subtasks){
subtasks.each {it ->
((MutableIssue) it).setCustomFieldValue(customField, change.newstring)
ComponentAccessor.getIssueManager().updateIssue(event.user, ((MutableIssue) it), EventDispatchOption.DO_NOT_DISPATCH, false)
}
}
}
Can you help me please ?
Thank you
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Rafael Moreira Hi
Use it:
def change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "labels"}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Folks,
This mine script (works for me)
Perhaps it helps to some1 else.
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
def event = event as IssueEvent
def change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "Contributors"}
if (event) {
def issue = event.issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def changeHolder = new DefaultIssueChangeHolder()
def targetField = customFieldManager.getCustomFieldObjects(event.issue).find {it.name == "Contributors"}
def sourceField = customFieldManager.getCustomFieldObjects(event.issue).find {it.name == "Contributors"}
targetField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(targetField), issue.getCustomFieldValue(sourceField)), changeHolder)
//update the UserPicker2 in subtasks as well - with the value of UserPicker from parent issue
issue.subTaskObjects?.each { subtask ->
targetField.updateValue(null, subtask, new ModifiedValue(subtask.getCustomFieldValue(targetField), issue.getCustomFieldValue(sourceField)), changeHolder)
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Guys,
I have a requirement where i need help.
When a custom field is getting updated in subtask , then changes should automatically reflect in parent task.
Please help
Thanks in advance.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Tanu,
Can you share your code snippet if your automation is working fine?
I too same requirement where I need few fields in the parent should sync to sub-tasks whenever there is a change in parent ticket.
thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The listener @Charles Huggins works perfectly for issues edits. The post functions that @Tanu pointed work great upon issue creation.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Charles Huggins ,
Can you pls help out with this script. I would like to update the Assignee field value Parent to Subtask. If i update Parent assignee field value it should update for all Subtasks. Please find my below script.
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
def event = event as IssueEvent
def change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "Assignee"}
log.warn("Assignee+++")
if (event) {
def issue = event.issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def changeHolder = new DefaultIssueChangeHolder()
def targetField = customFieldManager.getCustomFieldObjects(event.issue).find {it.name == "Assignee"}
def sourceField = customFieldManager.getCustomFieldObjects(event.issue).find {it.name == "Assignee"}
targetField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(targetField), issue.getCustomFieldValue(sourceField)), changeHolder)
log.warn("Target++++")
//update the UserPicker2 in subtasks as well - with the value of UserPicker from parent issue
issue.subTaskObjects?.each { subtask ->
targetField.updateValue(null, subtask, new ModifiedValue(subtask.getCustomFieldValue(targetField), issue.getCustomFieldValue(sourceField)), changeHolder)
log.warn("Target,,,,,,")
}
}
I'm getting below error
Thanks,
Sai
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.