Hello, I have been struggling to get a Listener script working. I am new to scripting. Hopefully someone can shed some light on what I need to do 
I want to keep a custom field (checkbox) up-to-date whenever anything changes in any of the subtasks. My current set up is:
- Sub-tasks have a 'Delivery Team' radio button picker
- The Parent issues of these sub-tasks have a 'Delivery Team(s)' checkbox field.
- This is designed to be a read-only field and reflects all of the selected Delivery Team values in each sub-task
- I currently have a post-function in the sub-task creation step that will push the value of Delivery Team into the parent's Delivery Team(s) property. This is done using the JSU plugin, so no code has been written. This part works fine
I want to make the process more robust and listen out for when any of the sub-tasks are updated and/or deleted, using a Scriptrunner Listener.
When the event fires on the sub-task I want to get the 'Delivery Team(s)' custom field from the parent issue and wipe it clean. I then want to loop through each of the sub-tasks, get the 'Delivery Team' custom field and add it to the 'Delivery Team(s)' custom field in the parent.
This way, whenever something changes in the sub-tasks I rebuild the 'Delivery Teams(s)' property in the parent issue
I am struggling to understand how to get the checkbox, wipe it clean and re-select options. Any help is greatly appreciated!
For info, this is the code I have so far, but is a long way off from doing anything!
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueFieldConstants.*
// Custom field identifiers
final String TEAM = "customfield_1234";
final String DELIVERY_TEAMS = "customfield_5678";
// Apply logic only to the Deliverable issue type
if (issue.getIssueType().name == "Deliverable") {
def parentIssue = issue.parentObject
def childIssues = parentIssue.getSubTaskObjects()
def cfTeam = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(TEAM)
def cfDeliveryTeams = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(DELIVERY_TEAMS)
// If the custom fields do not exist, exit
if (!cfTeam || !cfDeliveryTeams) {
return
}
//Clear the Delivery Team field in the parent Object
def cfDeliveryTeamsValue = parentIssue.getCustomFieldValue(cfDeliveryTeams)
// TODO: totally stuck here
// Cycle through each subtask to get the Delivery Team property value
childIssues.each {
//Add the Delivery Team property value to a List
// TODO
}
// Update Delivery Team(s) custom field with values from the sub-tasks
// TODO
} else {
// The event was not on a Deliverable ticket, so exit
return
}