Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

get the value of the "epic link" field

dmullor73 gmail April 21, 2021

Hello everybody.

I have created a script to find the value of the epic link field and add it to a new field. The script does not give me an error but it appends the object value of the "epic link" field in the new field

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.properties.APKeys
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.project.Project

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def checkLink = {link -> false}
def cFieldLinkEpica = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Epic Link'}

def cFieldEpicaAux = customFieldManager.getCustomFieldObject('customfield_13501')
issue.setCustomFieldValue(cFieldEpicaAux, cFieldLinkEpica)

The script I need is the following:

1. Let him check the type of problem.
2. Let him get the value of the "Epic Link" field for that problem.
3. If it is a subtask, find the value in the parent task of that subtask.
3. Add the value of the "epic link" field to the newly created field.

Thanks in advance

David

1 answer

0 votes
Nic Brough -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.
April 21, 2021

It's the line

def cFieldValueLinkEpica = issue.getCustomFieldValue(cFieldLinkEpica).toString()

throwing

com.atlassian.jira.issue.fields.ImmutableCustomField cannot be cast to java.lang.String

Epic Link fields do not contain strings.  You'll need to read the API Docs to find out how to get what you want out of it.  

dmullor73 gmail April 28, 2021

Hello,

I have made this new script in which it no longer gives me the error, but it does not load the internal value of the epic link field in the new field ...

Please can someone help me ... thank you.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.properties.APKeys
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.project.Project

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def checkLink = {link -> false}
def cFieldLinkEpica = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Epic Link'}

def cFieldEpicaAux = customFieldManager.getCustomFieldObject('customfield_13501')
issue.setCustomFieldValue(cFieldEpicaAux, cFieldLinkEpica)

Nic Brough -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.
April 29, 2021

This is because your "Aux Epic field" is not an Epic Link type field and you are now trying to put an Epic Link into it.  I suspect the content is actually an issue from https://library.adaptavist.com/entity/update-the-epic-link-for-an-issue-in-jira, so you'll probably need to extract something from the Epic you're trying to link to - summary, key, epic name etc.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
TAGS
AUG Leaders

Atlassian Community Events