Hi Community
I need a little bit of help with a scripted field and looking for ways to limit the returned results to specific projects. My scriptrunner knowledge is very basic and have not been able to work this out.
Below is the code the script field - it simply returns the issue keys for specific link type (we have several script fields like this) and they're used for reporting. A team wants to limit the return values of specific projects only - so if one of their issues is linked to multiple projects that are linked via that type ; they only want to show the results for a specific project.
E.g. Issue ABC-123 is linked via 'delivers' type to DEF-456 ; XYZ-789 ; XYZ-890 but team only wants to know what XYZ issues are linked. The current script returns all delivers issues for ABC-123.
import com.atlassian.jira.component.pico.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def cfManager = ComponentAccessor.getCustomFieldManager()
def retVal = ''
// Get only outward links
def links = issueLinkManager.getOutwardLinks(issue.id)
def itr = links.iterator()
while (itr.hasNext()) {
def link = itr.next()
// Only care about "Delivered by" link types
if (link.issueLinkType.name != 'Delivers') {
continue
}
// Get other issue
def linkedIssue = link.destinationObject
// Line seperators if more than one ticket
if (retVal != '') {
retVal += '<br>'
}
retVal += "${linkedIssue.getKey()} "
}
return retVal
This script field was setup by a previous admin so unable to get assistance from them. I looked at scriptrunner documentation and seen you can add JQL queries but I don't understand the code enough to put that into my existing script fields.
I appreciate any assistance the community can offer.
Regards, Jamie
Hi, try the following:
Note tht you must replace 'XYZ' with the desired project key to display
import com.atlassian.jira.component.pico.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def cfManager = ComponentAccessor.getCustomFieldManager()
def retVal = ''
// Get only outward links
def links = issueLinkManager.getOutwardLinks(issue.id)
def itr = links.iterator()
while (itr.hasNext()) {
def link = itr.next()
// Only care about "Delivered by" link types
if (link.issueLinkType.name != 'Delivers') {
continue
}
// Only care about linked issue of 'XYZ' project
if (link.destinationObject.projectObject.key != 'XYZ') {
continue
}
// Get other issue
def linkedIssue = link.destinationObject
// Line seperators if more than one ticket
if (retVal != '') {
retVal += '<br>'
}
retVal += "${linkedIssue.getKey()} "
}
return retVal
Thanks @Jack Nolddor _Sweet Bananas_ for the fast reply.
This works perfectly and meets the requirements for the teams that wanted this.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
HI @Jack Nolddor _Sweet Bananas_
I have a followup question - if i wanted to include two or three project's issues in the returned results but exclude the rest is there any easy way to do this?
E.g. I want to see linked issues from ABC, XYZ, JKL projects but not DEF or anyone else.
Would you be simply modifying this line in the script or adding additional code?
// Only care about linked issue of 'XYZ' project
if (link.destinationObject.projectObject.key != 'XYZ') {
continue
}
I really appreciate you help with this.
Regards, Jamie
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Just use this version instead:
import com.atlassian.jira.component.pico.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def cfManager = ComponentAccessor.getCustomFieldManager()
def retVal = ''
// Get only outward links
def links = issueLinkManager.getOutwardLinks(issue.id)
def itr = links.iterator()
while (itr.hasNext()) {
def link = itr.next()
// Only care about "Delivered by" link types
if (link.issueLinkType.name != 'Delivers') {
continue
}
// Only care about linked issue of given projects
def allowedProjects = ['ABC', 'XYZ', 'JKL']
if (!allowedProjects.contains(link.destinationObject.projectObject.key)) {
continue
}
// Get other issue
def linkedIssue = link.destinationObject
// Line seperators if more than one ticket
if (retVal != '') {
retVal += '<br>'
}
retVal += "${linkedIssue.getKey()} "
}
return retVal: :
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks again @Jack Nolddor _Sweet Bananas_ this does exactly what I need it to do.
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.
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.