Copy Epic Link label value into other label custom-field

Tova Pozen March 8, 2018

I'm trying to copy the value of the "Epic Link" custom field into other label custom field I have ("Feature Link", 'customfield_10602').

Here is the script listener code I wrote:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.issue.label.LabelManager
import com.atlassian.jira.issue.label.Label


//variables for issue re-index after changing the value
def issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService)
boolean wasIndexing = ImportUtils.isIndexIssues();

def issueMngr = ComponentAccessor.getIssueManager();
def cfMngr = ComponentAccessor.getCustomFieldManager();
Issue currentIssue = event.issue;
def epicLinkCfObj = cfMngr.getCustomFieldObjectByName('Epic Link');
String epicLinkValue = currentIssue.getCustomFieldValue(epicLinkCfObj);
def featureLinkLblCf = cfMngr.getCustomFieldObject('customfield_10602');
//def featureLinkValue = currentIssue.getCustomFieldValue(featureLinkLblCf);

featureLinkLblCf.updateValue(null,currentIssue, new ModifiedValue("", (Object) ([new Label(null, currentIssue.getId(),featureLinkLblCf.getIdAsLong(), epicLinkValue)] as Set)),
new DefaultIssueChangeHolder() )

//re-index issue after changing the value
issueIndexingService.reIndex(issueMngr.getIssueObject(currentIssue.id));
ImportUtils.setIndexIssues(wasIndexing);

 

The issue is, that the value copied into the label custom field ('customfield_10602') is the Epic Key, instead of the Epic Label.

As a sequence, when I run a JQL search by customfield_10602', I get a suggestion list of Epic keys instead of Epic names.

Feature Link search:

feature_link_search.PNG

 

vs search by epic link

search_by_epic_link.PNG

I have 3 question:

1. How can I retrieve the Epic Label value instead of the Epic Key value?
2. In case I manage to retrieve the Epic Label value, what values will be shown on the suggestions drop-down? Epic Name only? or Epic Name + Epic Key? (like when searching by "Epic Link")
3. As I've mentioned, the code works and updates the field, but throws an error on every IssueChangedEventImpl.

here is the error I get:

2018-03-08 14:35:19,807 ERROR [runner.AbstractScriptListener]: *************************************************************************************
2018-03-08 14:35:19,807 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueChangedEventImpl, file: <inline script>
com.atlassian.jira.util.dbc.Assertions$NullArgumentException: label should not be null!
	at com.atlassian.jira.util.dbc.Assertions.notNull(Assertions.java:25)
	at com.atlassian.jira.issue.label.Label.<init>(Label.java:26)
	at Script698.run(Script698.groovy:25)

 

 

What am I doing wrong?

 

 

 

2 answers

1 accepted

0 votes
Answer accepted
Randy
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.
April 6, 2018

lookup the issue by the epic key and read the epic name.

0 votes
Tova Pozen April 11, 2018

Thanks

That's what I was advised by ScriptRunner to do

Suggest an answer

Log in or Sign up to answer