Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Copy custom field data to a linked issue using groovy

Jeremy Schrecengost
Contributor
January 8, 2019

I have a ticket that has 10+ custom fields when that ticket transitions to a specific state I want to copy that data to the same custom fields for all the linked tickets (with a specific link type).

 

I have JMWE and that allows me to add a post function to do this but I would need to do one for each custom field. (unless someone knows how to adjust that)

What is the groovy code to access Custom Fields of a linked issue? I have been searching and I can only find how to create a link.

 

 

3 answers

1 accepted

0 votes
Answer accepted
Nir Haimov
Community Champion
January 8, 2019

How to get linked issues:

def issueManager = ComponentAccessor.getIssueManager() 
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def outwardIssueLinks = issueLinkManager.getOutwardLinks(issue.getId())

if (subOutwardElements.size() > 0) {
for (def i = 0; i < subOutwardElements.size(); i++ ) {
      def linkedIssue = issueManager.getIssueObject(subOutwardElements[i].destinationId)
    }
}
Nir Haimov
Community Champion
January 8, 2019

Once you got the linkedIssue, you access it's customfield same way as you would access any regular issue (it's anissue object), so:

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def myCustomField = customFieldManager.getCustomFieldObject("customfield_14949")

def linkedIssueCustomFieldValue = issueManager.getIssueObject(linkedIssue).getCustomFieldValue(myCustomField)
Jeremy Schrecengost
Contributor
January 9, 2019

Is there a way to only grab linked issues of a specific type? like "Is a copy of" 

Jeremy Schrecengost
Contributor
January 9, 2019

Also you have 

subOutwardElements.size

 

I am not seeing that defined anywhere should that be outwardIssueLinks?

Nir Haimov
Community Champion
January 9, 2019

Answer for both of your questions:

1. to search for specific link type:

def subOutwardElements = outwardIssueLinks.findAll { it.issueLinkType.name.contains("Is a copy of")}

2. In #1 you have the  "subOutwardElements"

0 votes
David Fischer
Community Champion
January 11, 2019

Here's the code:

issue.getLinkedIssues("Is a copy of").each {
it.setFieldValue("my field", issue.get("my field"))
}
0 votes
David Fischer
Community Champion
January 11, 2019

Since you're using JMWE, you can create a Scripted (Groovy) post-function, and on JMWE the code is much easier. I'll post an example later today

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, jira cloud certification, managing jira projects, jira project administration, jira cloud exam, atlassian certification, agile project management, jira workflows, jira permissions, jira training, jira cloud skills, atlassian learning

Become a Certified Jira Service Project Expert 🦸🏻‍♂️

Validate your expertise in managing Jira Service Projects for Cloud. Master configuration, optimize workflows, and manage users seamlessly. Earn global 🗺️ recognition and advance your career as a trusted Jira Service management expert.

Get Certified! ✍️
AUG Leaders

Atlassian Community Events