JIRA Cloud: Copy Epic Name to User Story Field Using Scriptrunner Post Function Transition

Chris Kaliveas June 22, 2019

Hi Everyone,

I'm having much difficulty finding solution tips for Jira Cloud. 

My objective is to take the Epic Name and add it to the Summary Field on a User Story on post create function via Scriptrunner. 

I am able to retrieve the "Epic Link" which is the Jira ID for the ticket....but I need to capture the Epic Name field.  If anyone can help me adjust my code below to obtain the Epic Name would do me wonders :-)

 

// get custom fields
def issueKey = issue.key

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

def strEnv = 'Enviroment'

def input_ver = customFields.find { it.name == 'Version' }?.id
def input2_env = customFields.find {it.name == 'Environment'}?.id
def input3_pdat = customFields.find {it.name == 'Proposed Due Date'}?.id

// Get Epic Link and Epic Name
def epic_link = customFields.find {it.name == 'Epic Link'}?.id
def epic_name = issue.fields[epic_link] as String

 

 

1 answer

1 accepted

0 votes
Answer accepted
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 2, 2019

Hi Chris,

Thank you for your question.

I can confirm that the Epic Link field only stores the key for the Epic which the issue is linked to.

This means that to get the name of the Epic that you need to make a separate rest call to the Get Epic API provided by Jira Software as described in the documentation page located here.

Using this API you can then pass the key of the Epic in order to return all its details which includes the name property that stores the name of the Epic.

Once you have got the name of the Epic and saved it to a variable then you can use this to set the summary of the issue and I can confirm that we have an example of how to set the summary on an issue inside the documentation example located here.

If this answer has solved your issue can you please accept it in order to mark this answer as correct for users who are searching for a similar issue.

Regards,

Kristian

Chris Kaliveas July 5, 2019

Hi Kristian, thank you for helping me out with this...much appreciated.  I'm bit rusty with the rest call in scriptrunner to obtain the epic name.  Any chance can you provide me an example using my code above to capture the epic name?

Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 8, 2019

Hi Chris,

Thank you for your response.

I have created a code sample located here based off your code which can be run on the Script Console and shows how you can get the Epic Name value using the Epic Link value off an issue.

You will be able to take this code sample and will be able to use it as a reference guide to help modify your script to achieve your requirements.

Regards,

Kristian

Like Daniel Tunjic likes this
Chris Kaliveas July 8, 2019

You are awesome...that was plug and play!!! worked like a charm.  Thanks heeps Kristian.

 

Cheers,

Chris

Suggest an answer

Log in or Sign up to answer