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:
vs search by epic link
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?
lookup the issue by the epic key and read the epic name.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.