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
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! :D
Aidan
@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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import 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 changed
def 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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
def 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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
def 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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
def 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)
}
}
}
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.
You re welcome! :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Mark Markov, and if its a Version Picker (multiple version) custom field? Is it possible to update the sub-tasks if a specific field from the parent issue is changed?
My situation is:
1 - Parent issue have a "x" custom field (Version Picker (multiple version))
2 - If that "x" custom field is changed I want to update the same field on it's sub-tasks.
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.
My field is a Select List - Single Choice. I have added your code but it is throwing a null value for my listener?
Any advice would be greatly appreciated!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Sam @Mark Markov < how do i update summary value in subtasks based on parent issue custom field automatically.
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.