Hi,
I want to update a custom field value in a sub-task if in the parent task the custom field value was updated, with Script Listeners.
The sub-task custom field and task custom field are the same field.
Thank you for your help.
Hello @Rafael Moreira,
You can create a script listener with IssueUpdated event and copy the code below. Hope this helps.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.user.ApplicationUser
String cfName = "CustomField name here" // Change this
Issue currentIssue = event.issue
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == cfName}
if(change) {
CustomField cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName(cfName)
Collection<Issue> subtasks = currentIssue.getSubTaskObjects();
for(MutableIssue subtask : subtasks){
subtask.setCustomFieldValue(cf, cf.getValue(currentIssue))
ComponentAccessor.getIssueManager().updateIssue(user, subtask, EventDispatchOption.DO_NOT_DISPATCH, false)
}
}
Do not forget to change cfName value with the customfield name you want.
Kind Regards.
Orkun Gedik
Hi,
Thank you for your answer, but I don't understand why I have this two errors that you can see in the print screen.
Can you help me please ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Rafael Moreira,
Sorry for typo. Can you try to change
getCustomFieldObjectsByName()
with
getCustomFieldObjectByName()
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.
Can you update the for loop as follows
for(Issue issue : subtasks){
MutableIssue subtask = (MutableIssue) issue
subtask.setCustomFieldValue(cf, cf.getValue(currentIssue))
ComponentAccessor.getIssueManager().updateIssue(user, subtask, EventDispatchOption.DO_NOT_DISPATCH, false)
}
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.
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.