/* * This script provides some example code that can be run on the script listeners page in Jira cloud and shows how to add a blcoks link to the issue when a child link has a blocks link. * This script should be configured to run on the Isseu Updated event. * 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." */// The JQL query to find all child issues below the parent issuedefjqlQuery="parent = ${issue.key}"// Run the JQL searchdefallChildIssues=get("/rest/api/2/search").queryString('jql',jqlQuery).header('Content-Type','application/json').asObject(Map).body.issues// Loop over all child issues returnedallChildIssues.each{childIssue->// Fetch the issue links for each child issuedefissueLinks=childIssue.fields.issuelinks// If the child issue contains issue linksif(issueLinks){// Check if the issue has a link type of "blocks" or is blocked by another issuedefhasBlocksLink=issueLinks.any{link->link.type.outward=="blocks"}defhasIsBlockedByLink=issueLinks.any{link->link.type.inward=="blocks"&&link.inwardIssue.key==issue.key}if(hasBlocksLink||hasIsBlockedByLink){// Create the issue link between both issuesdeflink=post('/rest/api/2/issueLink').header('Content-Type','application/json').body([type:[name:"Blocks"],outwardIssue:[key:issue.key],// This is the issue that the link 'starts' atinwardIssue:[key:childIssue.key]// You'll need to specify an issue ID or key here]).asString()}}}
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.