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,379
Community Members
 
Community Events
165
Community Groups

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

Edited

Hello!

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.link.IssueLink
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.issuetype.IssueType

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

// 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 comments

Comment

Log in or Sign up to comment
TAGS
Community showcase
Published in Jira Software

Upcoming changes to epic fields in company-managed projects

👋 Hi there Jira Community! A few months ago we shared with you plans around renaming epics in your company-managed projects. As part of these changes, we highlighted upcoming changes to epics on...

14,854 views 37 49
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