Copy Field Value from Parent Issue to Sub-task Upon Creation


Copy any field value from a parent issue to a newly created sub-task.


I have a custom field which dictates which components of work are needed. This information is the same for both parent issues and sub-tasks. This script means I don't need to enter these manually each time.

Good to Know

  • Implement this as the first post function on the Create step of a workflow.
  • fieldNameToCopy: Is the field name of the value to be copied.


Jira Jira (7.7 - 8.6)

import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.IssueFieldConstants import com.atlassian.jira.issue.fields.FieldManager // the name of the field whose value we want to copy from parent to subtask final String fieldNameToCopy = "Component/s" FieldManager fieldManager = ComponentAccessor.fieldManager if (!issue.isSubTask()) { return } def fieldToCopy = fieldManager.allAvailableNavigableFields.find { == fieldNameToCopy } if (!fieldToCopy) { "Could not find field with name $fieldNameToCopy" return } def parentIssue = issue.parentObject def fieldToCopyId = switch (fieldToCopyId) { case fieldManager.&isCustomFieldId: def customField = ComponentAccessor.customFieldManager.getCustomFieldObject(fieldToCopyId) def linkedIssueCustomFieldValue = parentIssue.getCustomFieldValue(customField) issue.setCustomFieldValue(customField, linkedIssueCustomFieldValue) break case IssueFieldConstants.COMPONENTS: issue.setComponent(parentIssue.components) break case IssueFieldConstants.FIX_FOR_VERSIONS: issue.setFixVersions(parentIssue.fixVersions) break case IssueFieldConstants.AFFECTED_VERSIONS: issue.setAffectedVersions(parentIssue.affectedVersions) break default: issue[fieldToCopyId] = parentIssue[fieldToCopyId] }
Discovered an issue? Report it here

Suggested for you

Appears in these Collections