Hi,
I would like to write a groovy script for that but I'm new to groovy and I'm not sure where to start.
I'm thinking about an auto-update or popup to decide which fields you would like to update.
Thanks for any suggestions
Hello @Sam
You can create Script listener, that will be triggers when your X field changes and update subtasks issues if they exist.
To create listener go Add-ons -> Script Listener ->Add -> Custom listener
Choose project you need, event Issue Updated (that means that listener will be triggered every time issues in you project updates)
And add script, for example:
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.event.type.EventDispatchOptionimport com.atlassian.jira.issue.MutableIssuedef change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "your X field name"}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("your X field name")if (subtasks){ subtasks.each {it -> ((MutableIssue) it).setCustomFieldValue(customField, change.newstring) ComponentAccessor.getIssueManager().updateIssue(event.user, ((MutableIssue) it), EventDispatchOption.DO_NOT_DISPATCH, false) } }}
do not forget to correct code with your fieldnames.
Hey there @Sam!
Mark's answer is essentially correct, but could fail depending on the type of field that you're working with. Some fields can just be set with a String, but others need a list of Option objects and other sorts of things.
What sort of field are wanting to copy over? For instance, is it a regular system field (one of the built-ins), or a custom field? If it's a system field, which? And if it's a custom field, what type? This information will help in getting you the most accurate solution possible.
Thanks! Aidan
Thank you for your answers. I've just started playing around with this script.I would like to update: Custom fields - string, Description field - string, Dates fields.
@Mark Markov
Hi Mark, I'm also trying to achieve this technique. However, instead of a string, the fields I am trying to update are custom field Radio Buttons. Here is the code I have so far, which is not working:
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.event.type.EventDispatchOptionimport com.atlassian.jira.issue.MutableIssuedef change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "Claim Approved"}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("Claim Approved") if (subtasks){ subtasks.each {it -> ((MutableIssue) it).setCustomFieldValue(customField, change.newstring) ComponentAccessor.getIssueManager().updateIssue(event.user, ((MutableIssue) it), EventDispatchOption.DO_NOT_DISPATCH, false) } }}
How would I modify this for a Radio Button?
And if you have time, how would you modify this for a select list with various options? (This one isn't critical for me at the moment, but I'm sure I'll need it down the road)
Thanks
Hello @Gavin Minnis
If you want to update selectlists, radio buttons, checkboxes fields you need to pass Option object, not string.
Here is example.
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.event.type.EventDispatchOptionimport com.atlassian.jira.issue.MutableIssuedef change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "Claim Approved"}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("Claim Approved")if (subtasks){ subtasks.each {it ->def options = ComponentAccessor.getOptionsManager().getOptions(customField.getRelevantConfig(it)) ((MutableIssue) it).setCustomFieldValue(customField, options.find {it.value == change.newstring}) ComponentAccessor.getIssueManager().updateIssue(event.user, ((MutableIssue) it), EventDispatchOption.DO_NOT_DISPATCH, false) } }}
Once again, you've solved my problem! Thanks, Mark.
@Aidan Derossett [Adaptavist]. you are correct. I am trying to set the value based on a "Version Picker (multiple version)" and I am having troubles to work with it. Is there any tutorial to help me?
I basically need to copy the value of a custom field (Version Picker (multiple version)) from my parent issue to it's subtasks.
@Mark Markov For some reason I can't get this script to work. I want to Fix Version/s -field to be updated and Script Listener shows "No failures in the last 4 execution(s)" but field in subtask is still out dated.
Hi @Sam @Mark Markov < how do i update summary value in subtasks based on parent issue custom field automatically.
Hi @Aidan Derossett [Adaptavist]
I'm looking for same script for Assignee system field need to update when i update in parent to subtask. Please help me out with below script.
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.event.type.EventDispatchOptionimport com.atlassian.jira.issue.MutableIssue
def change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "Assignee"}if (change) {log.debug "Value changed from ${change.oldstring} to ${change.newstring}"// your actions if the field has changeddef subtasks = event.issue.getSubTaskObjects()def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Assignee")if (subtasks){subtasks.each {it ->((MutableIssue) it).setCustomFieldValue(customField, change.newstring)ComponentAccessor.getIssueManager().updateIssue(event.user, ((MutableIssue) it), EventDispatchOption.DO_NOT_DISPATCH, false)}}
Thanks,
Sai
how do i update summary value in subtasks based on parent issue custom field automatically. <-- i also wanna know same answer
It looks like you're new here. Sign in or register to get started.