Get count of linked issues (get by link name and priority)

Stanislav Khudyakov
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 23, 2022


I need a script that will count all related issues with link name "has a defect" and priority in Blocker || Critical? and insert the counter number into the custom field.


So I wrote some script, it considers all related issues as Critical and Blocking priority, but I can't add check for inward link name "is defect of", can you please help me.


Thank you.


import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

import com.atlassian.jira.issue.issuetype.IssueType

def countS = ComponentAccessor.getIssueLinkManager().getLinkCollection(issue, issue.reporter)
.getAllIssues().count { in ['Critical', 'Blocker']

// custom field id
final long MY_CUSTOM_FIELD_ID = 14320;

// get issue to update
MutableIssue issue = ComponentAccessor.getIssueManager().getIssueByKeyIgnoreCase(issue.key);
// custom field reference
CustomField myCustomField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(MY_CUSTOM_FIELD_ID);
// construct the new value
ModifiedValue newValue = new ModifiedValue(issue.getCustomFieldValue(myCustomField), countS);
// update the field to "new value"
myCustomField.updateValue(null, issue, newValue, new DefaultIssueChangeHolder());


0 answers

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events