Search for the linked issuetype ( no matter what type of link it has)
Pull the result content : Issue id and summary
Current code an give only the number specific of linked issues, but cannot write the issue id
import com.atlassian.jira.component.ComponentAccessor def issueLinkManager = ComponentAccessor.getIssueLinkManager() def issueLinks = issueLinkManager.getInwardLinks(issue.getId()) def issueLinks1 = issueLinkManager.getOutwardLinks(issue.getId()) def subElements = issueLinks.findAll { it.issueLinkType.name =='UseCase_Link'} def subElements1 = issueLinks1.findAll { it.issueLinkType.name =='UseCase_Link'} log.error(subElements) return subElements.size()+subElements1.size() as Double
Hi Amar,
The code below gives you 3 collections of issues (1 Collection<Issue> and 2 List<Issue>). Then I suppose you can create a scripted field or update an existing custom field and you can store whatever information you want for the returned issues.
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue def issueManager = ComponentAccessor.getIssueManager() def issueLinkManager = ComponentAccessor.getIssueLinkManager() def applicationUser = ComponentAccessor.getJiraAuthenticationContext().user Issue issue = issueManager.getIssueObject("IssueKey") def linkCollection = issueLinkManager?.getLinkCollection(issue, applicationUser.directoryUser) // get the scripted field you want to save the result def tgtField = customFieldManager.getCustomFieldObjects(issue).find {it.name == "ScriptedFieldName"} //Returns a collection of issues that contains both inward and outward linking issues. def newValueForCF = '' def allLinkedIssues = linkCollection?.getAllIssues() def bugIssues = allLinkedIssues?.findAll {linkedIssue -> linkedIssue.getIssueTypeObject().name == 'Bug' } for (bug in bugIssues) { newValueForCF += "${bug.key} id: ${bug.id} - Summary: ${bug.summary} <br>" } //Return the value for the scripted custom field //return newValueForCF //Looks up and returns a "sort.order" sorted list of all inward linked issues by given link name. def inwardBlockIssues = linkCollection?.getInwardIssues('Blocks') inwardBlockIssues?.each {linkedIssue -> log.debug("Issue ${linkedIssue.key} - id: ${linkedIssue.id} - Summary: ${linkedIssue.summary}") } // Looks up and returns a "sort.order" sorted list of all outward linked issues by given link name. def outwardBlockIssues = linkCollection?.getOutwardIssues('Blocks') outwardBlockIssues?.each {linkedIssue -> log.debug("Issue ${linkedIssue.key} - id: ${linkedIssue.id} - Summary: ${linkedIssue.summary}") }
Thanks thanus. I want to condition and Group the issues by the type of issue. Such as linked issue is Task, then it the issue key and summary should be written in an another custom field
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Amar, I updated the above script. If you remove the return from comments, this script will add in a text scripted field the id and the summary of each linked issue that has 'bug' type
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Thanos,
I am using part of your script but having getting an error when compiling into a scripted field.
it returns expecting '}' found - on the def line
Could you let me know what I am doing wrong?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This ridiculous web site converted > to > etc... which is kind of a fatal flaw for any site where you are expected to put code.
I've tried to edit the answer to make it correct, please try now.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you very much Jamie,
I would appreciate it if you can have a look at the following code as it is now giving me an warning on def applicationUser that it is depreciated and cannot find matching method on
def linkCollection
def allLinkedIssues
def PatchIssues
// Code
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
def issueManager = ComponentAccessor.getIssueManager()
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def applicationUser = ComponentAccessor.getJiraAuthenticationContext().user
Issue issue = issueManager.getIssueObject("IssueKey")
def linkCollection = issueLinkManager?.getLinkCollection(issue, applicationUser.directoryUser)
//Returns a collection of issues that contains both inward and outward linking issues for the issuetype Patch.
def allLinkedIssues = linkCollection?.getAllIssues()
def PatchIssues = allLinkedIssues?.findAll {linkedIssue -> linkedIssue.getIssueTypeObject().name == 'Patch' }
PatchIssues.toString()
//
I am trying to count the number of linked Patches to an issue
Kind regards,
Marco
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Amar, You want all the linked issues or the issues that are linked via a specific issue link type (in your case the UseCase_Link) ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.