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!
Community moderators have prevented the ability to post new answers.
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.
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...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yeah use "issue" rather than currentIssue without defining it
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Cool! I'm not sure why you need the io variable - can't you just use issueObject?
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.