/* * "This script console script can be ran on the Script Console inside of Jira Cloud to show how you can return all of the linked issues for an issue and perform a transition on the issue if all of the * linked issues are in a Closed status. * All right, title and interest in this code snippet shall remain the exclusive intellectual property of Adaptavist Group Ltd and its affiliates. Customers with a valid ScriptRunner * license shall be granted a non-exclusive, non-transferable, freely revocable right to use this code snippet only within their own instance of Atlassian products. This licensing notice cannot be removed * or amended and must be included in any circumstances where the code snippet is shared by You or a third party." *///specifytheissuekey
defissueKey="<IssueKeyHere>"//Specifythenameoftheversiontoextractfromtheissue
defclosedStatus='<ClosedStatusHere>'//Specifythetransitiontoexecuteontheissue
//NOTE-ThetransitionIDmustrepresentavalidtransitionfortheworkflowthattheissueuses.deftransitionID='<TransitionIDHere>'//Specifyabooleantoflagifallissuelinksareresolved
booleanallIssueLinksResolved;//Gettheissueobject
defresult=get('/rest/api/2/issue/'+issueKey).header('Content-Type','application/json').asObject(Map)//Findthelinkedissues
deflinkedIssues=result.body.fields.issuelinks
//ifallissuelinkshavetheDonestatussettheflagtotrue
if(linkedIssues.findAll{closedStatus.contains(it.outwardIssue.fields.status.name)}){allIssueLinksResolved=true
}//Ifanyofthelinkedissuesdonothavethedonestatussettheflagtofalse
if(linkedIssues.findAll{!closedStatus.contains(it.outwardIssue.fields.status.name)}){allIssueLinksResolved=false
}//Ifallissuelinksareresolvedtransitiontheissue
if(allIssueLinksResolved==true){//Therestcalltotransitiontheissue
deftransitionIssue=post("/rest/api/2/issue/${issueKey}/transitions").header("Content-Type","application/json").body([transition:[id:transitionID]]).asObject(Map)return"All issue links are to closed issues and the issue has been transitioned."//Iftheissuecontainsunresolvedlinkedissuesreturnamessageanddonottransitiontheissue
}elseif(allIssueLinksResolved==false){return"The issue contain issue links which are not closed"}
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.