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.
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)
}
}
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is there a way to only grab linked issues of a specific type? like "Is a copy of"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Also you have
subOutwardElements.size
I am not seeing that defined anywhere should that be outwardIssueLinks?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here's the code:
issue.getLinkedIssues("Is a copy of").each {
it.setFieldValue("my field", issue.get("my field"))
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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.