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

Inward/Outward links in groovy, only one way working

B_ Normann P_ Nielsen
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 9, 2014

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".

5 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 9, 2014

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)
    }
}
B_ Normann P_ Nielsen
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 9, 2014

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.

0 votes
Prashant Mali June 6, 2017

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

0 votes
B_ Normann P_ Nielsen
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 10, 2014

Thanks again Jamie, as always You very correct and leading me in the right direction smile

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

Lacey McDonnell December 28, 2016

Trying to figure this out myself and man I have no idea what you're saying there.

0 votes
B_ Normann P_ Nielsen
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 10, 2014

done, thats the least I can do :-)

0 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 9, 2014

Any chance you could some groovy tag so the right people see these?

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events