I have the following script:
import com.atlassian.jira.ComponentManager import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.link.IssueLink; def componentManager = ComponentManager.getInstance() def issueLinkManager = ComponentAccessor.getIssueLinkManager() import org.apache.log4j.Category import com.atlassian.jira.issue.comments.CommentManager import com.opensymphony.workflow.WorkflowContext import com.atlassian.jira.workflow.WorkflowTransitionUtil; import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl; import com.atlassian.jira.util.JiraUtils; def Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction") log.setLevel(org.apache.log4j.Level.DEBUG) log.debug "debug statements" String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller(); WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class ); issueLinkManager.getOutwardLinks(issue.id)?.each {issueLink -> if (issueLink.issueLinkType.name == "parent-child") { // Transist Issue workflowTransitionUtil.setIssue(issueLink.getDestinationObject()); workflowTransitionUtil.setUsername(currentUser); workflowTransitionUtil.setAction (741) // 741 = Waiting // validate and transition issue workflowTransitionUtil.validate(); workflowTransitionUtil.progress(); // Add a comment so people have a clue why the child has been closed CommentManager commentManager = (CommentManager) ComponentManager.getComponentInstanceOfType(CommentManager.class); String comment = "Status changed to *WAit for solution* as a result of the *Resolve* action being applied to the TD Issue."; commentManager.create(issueLink.getDestinationObject(), currentUser, comment, true); } }
I want 2 linked issues "A" and "B" to update each other, but the linking only works one way "A" to "B" - when I use
getOutwardLinks.... On the other issue "B" to get hold of "A" - the return of getOutwardLinks is empty, and
getInwardLinks seems to be the issue "B" itself, and not the linked issue "A".
Community moderators have prevented the ability to post new answers.
Use getDestinationObject
with getOutwardLinks
.
With getInwardLinks
use getSourceObject
.
You may be doing that already, but from a quick scan of your code I don't see that.
I use code like this...
def links = linkDirection == OUTWARD ? issueLinkManager.getOutwardLinks(issue.id) : issueLinkManager.getInwardLinks(issue.id) links.each { if ((it.issueLinkType == config.linkType) || ! config.linkType) { def linkedIssueId = linkDirection == OUTWARD ? it.destinationId : it.sourceId issueIds << (linkedIssueId as String) } }
Hi, Thanks for the answer, but the "problem" is before I reach getSourceObject or getDestinationObject The Loop: issueLinkManager.getInwardLinks(issue.id)?.each {issueLink -> if (issueLink.issueLinkType.name == "Awaits") { is never active, as if no links are found. I will look at your answer and test a bit more later.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Not working for me...
I want to copy comment from one issue to linked issue and vice versa.
one way is working, but not working for other way. I want to user same script to do that.
Please suggest
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks again Jamie, as always You very correct and leading me in the right direction
The solution was to use
issueLinkManager.getOutwardLinks(issue.id)?.each {issueLink ->
on both "A" and "B" - and then getDestinationObject in the script for "A" -> "B" in the Loop and getInwardLinks on "B" -> "A"
Best JIRegards,
Normann
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Trying to figure this out myself and man I have no idea what you're saying there.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
done, thats the least I can do :-)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Any chance you could some groovy tag so the right people see these?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.