Snippets

Adaptavist Jira Cloud - Script Console Get Epic Name from Epic Link Value

Created by Kristian Walker last modified
/*
* This example script  console script returns the name and key of the linked EPIC based on the value from the Epic Link Field on the issue .
* "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." 
*/

// Specify the issue key below
def issueKey = "<IssueKeyHere>"

// Get the custom fields for the Jira Instance
def customFields = get("/rest/api/2/field")
.asObject(List)
.body
.findAll { (it as Map).custom } as List<Map>

// Get the Id for the Epic Link and Epic Name fields 
def epic_link_Id = customFields.find {it.name == 'Epic Link'}?.id

// Get all of the field values from the issue
def issue = get('/rest/api/2/issue/' + issueKey)
        .header('Content-Type', 'application/json')
        .asObject(Map) 

// Get the value from the Epic Link Field
def epic_link_value = issue.body.fields[epic_link_Id]

// Get the Epic
def epic = get("/rest/agile/1.0/epic/${epic_link_value}")
        .header('Content-Type', 'application/json')
        .asObject(Map)

// Get the name from the returned Epic        
def epic_name_value = epic.body.name as String

def epic_key_value = epic.body.key as String

// Print out the returned name on screen
return "Epic Name = ${epic_name_value} and Epic Key = ${epic_key_value}"
        

Comments (0)

HTTPS SSH

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