Hi Team,
I have IssueType called 'Initiative' & 'EPIC', whenever I create an EPIC I will link Initiative using Issue link picker field type 'Initiative Link', as part of this process I want to link the same issue whatever I selected as 'Initiative Link' to be linked to my EPIC as 'child of' & same should be viewed in the issue link section of 'Initiative' with 'parent of' relation, in attempt to do this, I have created behavior for the field 'Initiative Link', so whenever this value is selected during create/Edit, it should update the issue-links with the same issue selected.
I have written the code like this, but I get an error when I run in console & same is not working in behavior too, not having any compilation error though but get some run time error
---------- 'org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'ABC-1617' with class 'com.atlassian.jira.issue.IssueImpl' to class 'java.lang.Long'
at Script784$_run_closure1.doCall(Script784.groovy:16)
at Script784.run(Script784.groovy:14)' ---------------
My code is
---------------------------------------------------------------------
---------------------------------------------------------------------
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.component.ComponentAccessor
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def jiraAuthContext = ComponentAccessor.getJiraAuthenticationContext()
def long tpIssueLinkType = 12030
def MutableIssue cfIssue
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
CustomField customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_14771")
Issue issue = issueManager.getIssueByCurrentKey("ABC-1703")
issue.getCustomFieldValue(customField).each
{ iscr -> cfIssue = issueManager.getIssueObject((Long)iscr) issueLinkManager.createIssueLink(cfIssue.getId(), issue.getId(), tpIssueLinkType, 1L, currentUser) }
----------------------------------------------------------------------
----------------------------------------------------------------------
thanks,
JY
Though this is working when I modify/update the 'Initiative Link' field in the existing issues, but not working when I create a ticket having the same 'Initiative Link', also I need this to remove if existing any '12030 ' issue link and add updated Initiative Link.
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.IssueEvent
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def long tpIssueLinkType = 12030 // Initiative Issue Link
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
CustomField customField = customFieldManager.getCustomFieldObject("customfield_14771") // Initiative Link Field
Issue sourceIssue = issueManager.getIssueByCurrentKey(underlyingIssue?.getKey()) // Get Underlying issue key
sourceIssue.getCustomFieldValue(customField).each {
iscr ->
def cfIssue = issueManager.getIssueByCurrentKey((String)iscr)
issueLinkManager.createIssueLink(cfIssue.id, sourceIssue.id, tpIssueLinkType, 1L, currentUser)
}
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.