Hi!
I have a problem - trying to copy value of Group picker to Sub-Task via behaviour.
But it's not working 
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.web.util.OutlookDate
import com.atlassian.jira.web.util.OutlookDateManager
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import groovy.transform.BaseScript
import java.sql.Timestamp
import static com.atlassian.jira.issue.IssueFieldConstants.AFFECTED_VERSIONS
import static com.atlassian.jira.issue.IssueFieldConstants.ASSIGNEE
import static com.atlassian.jira.issue.IssueFieldConstants.COMPONENTS
import static com.atlassian.jira.issue.IssueFieldConstants.DESCRIPTION
import static com.atlassian.jira.issue.IssueFieldConstants.DUE_DATE
import static com.atlassian.jira.issue.IssueFieldConstants.ENVIRONMENT
import static com.atlassian.jira.issue.IssueFieldConstants.FIX_FOR_VERSIONS
import static com.atlassian.jira.issue.IssueFieldConstants.LABELS
import static com.atlassian.jira.issue.IssueFieldConstants.PRIORITY
import static com.atlassian.jira.issue.IssueFieldConstants.SECURITY
import static com.atlassian.jira.issue.IssueFieldConstants.SUMMARY
@BaseScript FieldBehaviours fieldBehaviours
FormField field = getFieldById(getFieldChanged())
FormField parent = getFieldById("parentIssueId")
Long parentIssueId = parent.getFormValue() as Long
if (!parentIssueId || field.getFormValue()) {
// this is not a subtask, or the field already has data
return
}
def issueManager = ComponentAccessor.getIssueManager()
def parentIssue = issueManager.getIssueObject(parentIssueId)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
// REMOVE OR MODIFY THE SETTING OF THESE FIELDS AS NECESSARY
//getFieldById(SUMMARY).setFormValue(parentIssue.summary)
//getFieldById(PRIORITY).setFormValue(parentIssue.getPriorityObject().id)
OutlookDate outlookDate = ComponentAccessor.getComponent(OutlookDateManager).getOutlookDate(Locale.getDefault())
//getFieldById(DUE_DATE).setFormValue(outlookDate.formatDMY(parentIssue.getDueDate()))
//getFieldById(COMPONENTS).setFormValue(parentIssue.componentObjects*.id)
//getFieldById(AFFECTED_VERSIONS).setFormValue(parentIssue.affectedVersions*.id)
//getFieldById(FIX_FOR_VERSIONS).setFormValue(parentIssue.fixVersions*.id)
//getFieldById(ASSIGNEE).setFormValue(parentIssue.assigneeId)
//getFieldById(ENVIRONMENT).setFormValue(parentIssue.environment)
//getFieldById(DESCRIPTION).setFormValue(parentIssue.description)
//getFieldById(SECURITY).setFormValue(parentIssue.securityLevelId)
//getFieldById(LABELS).setFormValue(parentIssue.labels)
//getFieldById(LABELS).setFormValue(parentIssue.labels)
// IF YOU DON'T WANT CUSTOM FIELDS COPIED REMOVE EVERYTHING BELOW HERE
// IF YOU ONLY WANT SOME FIELDS INHERITED ADD THEM TO THE LIST BELOW, OR LEAVE EMPTY FOR ALL
// eg ['Name of first custom field', 'Name of second custom field']
List copyCustomFields = ['Grupa obsługująca']
List<CustomField> parentFields = customFieldManager.getCustomFieldObjects(parentIssue)
parentFields.each { cf ->
if (copyCustomFields && !copyCustomFields.contains(cf.name)) {
return
}
def parentValue = cf.getValue(parentIssue)
if (!parentValue) {
return
}
getFieldById(cf.id).setFormValue(parentValue)
log.debug("parentValue: ${parentValue?.class} for type ${cf.name}")
if (parentValue instanceof Timestamp) {
getFieldById(cf.id).setFormValue(outlookDate.formatDMY(parentValue))
} else if (parentValue instanceof Option) {
getFieldById(cf.id).setFormValue(parentValue.optionId)
} else if (parentValue instanceof List<Option>) {
parentValue = parentValue as List<Option> //This cast is just to placate the static type checker
getFieldById(cf.id).setFormValue(parentValue.collect { it.optionId })
} else {
getFieldById(cf.id).setFormValue(parentValue)
}
}