Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,298,143
Community Members
 
Community Events
165
Community Groups

issue link script problem

Edited

Im trying to read  the linked issues of a specific issue. But the script is only reading the epic link issue.

PA-2000 have a linked issue  OB-1111 also have and epic Link = OB-50

I want to make a transition on OB-1111 but the script never read it. the script only reads the epic link OB-50


following my code.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.issuetype.IssueType
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.bc.issue.*
import static com.atlassian.jira.workflow.TransitionOptions.Builder;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.link.IssueLink


MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject("PA-2000");
IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager();


for (IssueLink issueLink in issueLinkManager.getInwardLinks(issue.id)) {

MutableIssue linkedIssue = (MutableIssue) issueLink.getSourceObject();
log.warn(linkedIssue.key)
log.warn(linkedIssue.getIssueType().getName())
if (issueLink.issueLinkType.name == "blocks" && linkedIssue.getProjectObject().getKey().contains("OSP") && linkedIssue.getStatus().getName().contains("In Research")){
log.warn("OK ")
if (linkedIssue.getIssueType().getName() != "Epic"){
log.warn("IS NOT EPIC")
IssueInputParameters issueInputParameters = ComponentAccessor.getIssueService().newIssueInputParameters();
com.atlassian.jira.workflow.TransitionOptions trasitionOptions = new Builder().skipPermissions().skipValidators().setAutomaticTransition().skipConditions().build();
IssueService issueService = ComponentAccessor.getIssueService();
int actionId = 921;
IssueService.TransitionValidationResult transitionValidationResult = issueService.validateTransition(issue.getReporterUser(), linkedIssue.getId(), actionId, issueInputParameters, trasitionOptions);
IssueService.IssueResult transitionResult

if (transitionValidationResult.isValid()) {

transitionResult = issueService.transition(issue.getReporterUser(), transitionValidationResult);

}else if (!transitionValidationResult.isValid()) {

log.error("ERROR: " + transitionValidationResult.getErrorCollection());
}
}
}



2 answers

1 accepted

0 votes
Answer accepted

 found the error.

replacing

for (IssueLink issueLink in issueLinkManager.getInwardLinks(issue.id)) {

MutableIssue linkedIssue = (MutableIssue) issueLink.getSourceObject();

for...

for (IssueLink issueLink in issueLinkManager.getOutwardLinks(issue.id)) {

MutableIssue linkedIssue = (MutableIssue) issueLink.getDestinationObject();

What is the issue link type id of both issues? Are they both blocing the source issue? You are only checking inwards links. That might be the issue.

check outward links from PA-2000 e.g

            List<IssueLink> allOutIssueLink = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId());

            for (Iterator<IssueLink> outIterator = allOutIssueLink.iterator(); outIterator.hasNext();) {
                IssueLink issueLink = (IssueLink) outIterator.next();
                String key = issueLink.getDestinationObject().getKey();
               log.warn("linked issued:: "+key)

               

}

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence

An update on Confluence Cloud customer feedback – June 2022

Hi everyone, We’re always looking at how to improve Confluence and customer feedback plays an important role in making sure we're investing in the areas that will bring the most value to the most c...

155 views 1 3
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you