Copy EPIC Link to standard JIRA Linked Issues

Azfar Masut
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 11, 2019

Hi Folks!

Currently, I have a need to switch an EPIC issue type to just a normal issue type (its a long story - we're consolidating a really bad JIRA instance that has no proper strategy on maintaining their issue properly, so we had to restrategize the process again).

The problem is, when we change the issue type from EPIC to a standard issue type, the EPIC link would be gone. We would like convert this link as just a standard issue link and manage things further using BigPicture.

Have anyone able to perform this using scriptrunner before? Basically copying the EPIC link values(or epic issue key) into the standard issue link (on child level).

Is this even possible to be done? Or is there any better way to do this?

2 answers

1 accepted

1 vote
Answer accepted
Azfar Masut
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 25, 2019

This is the final look of the script together with JQL:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter

def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def linkManager = ComponentAccessor.getIssueLinkManager()
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

//JQL Query - replace accordingly
def query = jqlQueryParser.parseQuery("issuefunction in linkedIssuesOf('project = NESCOM', 'is Epic of')")

def results = searchProvider.search(query, currentUser, PagerFilter.getUnlimitedFilter())
log.warn("Total issues: "+ results.total)

//Passing to temp
results.getIssues().each {documentIssue ->
//log.warn("documentIssue.key: " + documentIssue.key)

def issue = issueManager.getIssueObject(documentIssue.id)

// This line is for avoid do it for Epic issues
if(issue.getIssueType().getName() != "Epic"){
def epicLinkField = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Epic Link"}
//log.warn("epicLinkField: " + epicLinkField)
def epicLinkFieldValue = issue.getCustomFieldValue(epicLinkField)
//log.warn("epicLinkFieldValue: " + epicLinkFieldValue)

//To pass the epic issue key in string format
String TargetIssueString = epicLinkFieldValue
//To translate the epic issue key to ID
def TargetIssue = issueManager.getIssueObject(TargetIssueString)
// log.warn("TargetIssue: " + TargetIssue.id)

if (epicLinkFieldValue) {
//create the issue link, target,source,linktype,positioning,runuser
linkManager.createIssueLink(TargetIssue.id,issue.id,10400,1,currentUser)
issueManager.updateIssue(currentUser, issue, EventDispatchOption.DO_NOT_DISPATCH , false)
log.warn("documentIssue.key: " + documentIssue.key)
log.warn("epicLinkFieldValue: " + epicLinkFieldValue)
}
}
}

 Thanks to @jmarquesadaptavist from Scriptrunner for guiding me on this!

0 votes
Azfar Masut
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 11, 2019

From https://community.atlassian.com/t5/Jira-questions/Copy-Epic-Link-label-value-into-other-label-custom-field/qaq-p/745780 I can see that the value passed by EPIC link can be passed as the EPIC key, and from https://community.atlassian.com/t5/Jira-questions/Copy-Issue-Picker-value-s-to-Linked-Issue-Field/qaq-p/1112392 , seems like its possible to copy field values into Linked Issues field. I'm a total beginner in scripting, so if there's anyone out there can advise on this, it would be greatly appreciated! Thanks!

jmarquesadaptavist October 23, 2019

Hi Azfar, 

Thank you for opening a Ticket with this question on Adaptavist Support Portal.

Follow bellow your accepted answer:

I've created an example by copying the value from an Epic link field to a Single Issue Picker and as you can see in the video below it worked well. 

https://drive.google.com/file/d/1C3RyVv9atzCkTEMCelzIoh60sMqDgSgW/view?usp=sharing

Here you can see the script in detail. Please, read all the comments in order to adapt to your case. 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption

def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

// The line below is just used to test in the script consoledef issue = issueManager.getIssueObject("TEST-3")

def epicLinkField = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Epic Link"}
log.warn("epicLinkField: " + epicLinkField)
def epicLinkFieldValue = issue.getCustomFieldValue(epicLinkField)
log.warn("epicLinkFieldValue: " + epicLinkFieldValue)

// Here is your custom field namedef issueLinkField = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Single Issue Picker"}
log.warn("issueLinkField: " + issueLinkField)
def issueLinkFieldValue = issue.getCustomFieldValue(issueLinkField)
log.warn("issueLinkFieldValue: " + issueLinkFieldValue)

if (epicLinkFieldValue) {
    issue.setCustomFieldValue(issueLinkField, epicLinkFieldValue)
    issueManager.updateIssue(currentUser, issue, EventDispatchOption.DO_NOT_DISPATCH , false)
}

Many Thanks and Kind Regards, 

Jose

Adaptavist

Suggest an answer

Log in or Sign up to answer