Snippets

Adaptavist ScriptPostFunctionSetEpicNametoSummaryValue

Created by Kristian Walker
/*
 * "This script post function script provides an example script of how to set the 'Epic Name' Field to the value of the summary field when an issue is created. 
 * Note - As this post function runs on the create transition then it should be ordered after the post function which creates the issue so that the issue is created before the value is copied. 
 * All right, title and interest in this code snippet shall remain the exclusive intellectual property of Adaptavist Group Ltd and its affiliates. Customers with a valid ScriptRunner 
 * license shall be granted a  non-exclusive, non-transferable, freely revocable right to use this code snippet only within their own instance of Atlassian products. This licensing notice cannot be removed
 * or amended and must be included in any circumstances where the code snippet is shared by You or a third party." 
 */
 
 // To restrict this code to run only on 'Epic' issue types add in the condition below to the conditions box and uncomment it.
 // ((Map) issue.fields.issuetype)?.name == 'Epic'
 
 // Get the issue key for the current issue
def issueKey = issue.key

// Get the ID for the Epic Name Custom Field
def epicNameCustomField = get("/rest/api/2/field")
        .asObject(List)
        .body
        .find {
    (it as Map).name == 'Epic Name'
} as Map

logger.info("epicNameCustomField ID is " + epicNameCustomField.id)

// Update the issue with the value of the summary field 
def result = put("/rest/api/2/issue/${issueKey}")
        .header('Content-Type', 'application/json')
        .body([
                fields: [
                        (epicNameCustomField.id): issue.fields.summary
                ]
        ])
        .asString()

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.