It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Copy EPIC Link to standard JIRA Linked Issues Edited

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

0 votes
Answer accepted

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!

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!

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
Community showcase
Posted in Jira

Demo Den Ep. 7: New Jira Cloud Reports

Learn how to use two new reports for next-gen projects in Jira Cloud:  Cumulative flow diagram and Sprint burndown chart. Ivan Teong, Product Manager, Jira Software, demos the Cumulative ...

334 views 1 3
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you