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

Check if linked issue is in a certain project

Anton Haglund August 1, 2016

Hi all,

We want to comment a linked issue when the first issue is resolved. However, the issue can have multiple linked issues and we just want to comment those who belongs to a certain project, Project B. Our idea is to use the post-function "Comment linked issues" and have a Groovy script condition that checks this.

We have tried to look at other examples and we think that we should start off with something like suggested in this thread: https://answers.atlassian.com/questions/164360/transition-issue-when-all-linked-issues-are-resolved

We simply want it to only comment on the linked issues that belongs to Project B. Our initial code was: 

issueObject().getProjectObject().getKey() = ="Project B"

But we realized that this only looks at the current issue's Project and not the Project of the linked issue. We are trying with something like the code below, but we can't get it to work.  

link.getDestinationObject().getProjectObject().getKey() == "Project B"

 

All help would be very much appreciated!

Thanks!

 

2 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
Petar Petrov (Appfire)
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.
August 1, 2016

Use IssueLinkService.getIssueLinks to get the all linked issues - iterate over the LinkCollection and check if each linked issue belongs to the project in question. If you are interested in only specific link types, you can use some of the other methods in IssueLinkService to filter the links collection.

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.
August 1, 2016

What Petar said... note that:

link.getDestinationObject().getProjectObject().getKey() == "Project B"

is unlikely to be what you want, the key is something like PROJB.

Otherwise it looks correct...

Anton Haglund August 1, 2016

Hi and thanks for your reply,


We believe we've made progress but are still encountering some problems. This is what we've got so far:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue;

Issue currentIssue
String currentIssueKey = currentIssue.getKey()
def issue = ComponentAccessor.getIssueManager().getIssueObject(currentIssueKey)
def issueLinkManager = ComponentAccessor.getIssueLinkManager()

issueLinkManager.getOutwardLinks(issue.id).any{it.destinationObject.getProjectObject().getKey()
== 'SATO'}


The problem is that we want this condition to be applicable to all issues, meaning we don't want to manually enter the issue key (variable currentIssueKey on line 10). We've tested the code in the Script Console and it seems to work fine besides this.

Do you know if there's a way to get the key of the current issue (because now the currentIssue is null since Issue is an interface). We've tried Issue issue = issue but it doesn't work.

Thanks!

Petar Petrov (Appfire)
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.
August 1, 2016

If you are using Script Runner, then you should be able to reference the "issue" variable in the script of a workflow function (in your case - condition) without any additional code - see here (section Script Binding).

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.
August 2, 2016

Yeah use "issue" rather than currentIssue without defining it

0 votes
Anton Haglund August 3, 2016

Hi guys, 

Thanks for your answers! We finally got the code to work, here is the final version. Hope it can help someone else! 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.MutableIssue

def io = ComponentAccessor.getIssueManager().getIssueObject(issueObject.getKey())
def issueLinkManager = ComponentAccessor.getIssueLinkManager()

issueLinkManager.getOutwardLinks(io.id).any{it.destinationObject.getProjectObject().getKey()
== 'SATO'}

Best, 
Anton 

Petar Petrov (Appfire)
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.
August 3, 2016

Cool! I'm not sure why you need the io variable - can't you just use issueObject?

TAGS
AUG Leaders

Atlassian Community Events