Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Block the issue transition based on linked issue status or completion in Server using script runner

Abhishree Nagesh
Contributor
February 6, 2019

Hi,

jira is running on Server.

Script Runner for Jira is used.

Issue is linked, untill the linked issue is close ..the issue from which it is linked must not be able to move to next status.

Code is required, Please help me.

Regards,

Abhishree Nagesh

1 answer

0 votes
Gezim Shehu [Communardo]
Community Champion
February 6, 2019

There might by typos, but I think this does the trick.

Script below checks all linked issues (careful to specify link type and inward/outward) and checks if any of the linked issue has a status not equal to Closed , it returns false

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.MutableIssue
 
Issue sourceIssue = issue
def List<IssueLink> allIssueLinks
List<Issue> allLinkedIssues = new ArrayList<Issue>()
def String initialLinkName = 'linkTypeName'
def String linkType = 'yourLinkType'
def boolean passesCondition = true //default is true, only change to false if any of linked issues is not closed
def linkedIssueStatus = 'Closed'


//depending on link type, either use inward or outward links
switch(linkType){
    case 'Inward':   
        allIssueLinks = ComponentAccessor.getIssueLinkManager().getInwardLinks(sourceIssue.getId())
        if(allIssueLinks){
            for(Iterator<IssueLink> iterator = allIssueLinks.iterator(); iterator.hasNext();) {
                IssueLink issueLink = (IssueLink) iterator.next()
                String linkName = issueLink.getIssueLinkType().getName()
                if(linkName.equals(initialLinkName)){
                    allLinkedIssues.add(issueLink.getSourceObject())  
                }
            }
        }
        break
       case 'Outward':
        allIssueLinks = ComponentAccessor.getIssueLinkManager().getOutwardLinks(sourceIssue.getId())
        if(allIssueLinks){
            for(Iterator<IssueLink> iterator = allIssueLinks.iterator(); iterator.hasNext();) {
                IssueLink issueLink = (IssueLink) iterator.next()
                String linkName = issueLink.getIssueLinkType().getName()
                if(linkName.equals(initialLinkName)){
                    allLinkedIssues.add(issueLink.getDestinationObject())
                }
            }
        }
        break
    default :
        break
}
 
if(allLinkedIssues){
    //check linked issues
    for(Issue linkedIssue : allLinkedIssues){
        if(linkedIssue.getStatus().getName() != linkedIssueStatus ){
            passesCondition = false
        }
    }
}
return passesCondition
//x
Abhishree Nagesh
Contributor
February 6, 2019

@Gezim Shehu [Communardo]

Thank you for your quick reply ..but i  have no idea what has to be edited in the 

def String initialLinkName = 'linkTypeName'
def String linkType = 'yourLinkType'

so please help me .

Regards,

Abhishree Nagesh 

Gezim Shehu [Communardo]
Community Champion
February 7, 2019

Hi @Abhishree Nagesh,

linkTypeName - this is the link type name (example : Relates, Request, Duplicate) etc

 

linkType - defines if the link is initiated from the actual issue (outward) or if some other issue is linking to the current issue (inward). this you can just try with your linked issue :)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events