Hi All, we have a requirement to restrict the Linked Issue relationship on a certain project to 'Contains' and 'Contained in'. We initially copied some code from Adaptavist - Control Available Issue Link Types - Adaptavist Library
However, copying the full code and modifying for our required relationships, throws up a text type error. When we removed the last line of code, ScriptRunner likes it, and executes successfully, but it doesn't actual work!?
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLinkTypeManager
import com.onresolve.jira.groovy.user.FieldBehaviours
import org.apache.log4j.Logger
import org.apache.log4j.Level
import groovy.transform.BaseScript
def log = Logger.getLogger(getClass())
log.setLevel(Level.DEBUG)
def linkTypesField = getFieldById("issuelinks-linktype")
def allowedOutwardTypesNames = ["contains"]
def allowedInwardTypesNames = ["is contained in"]
def issueLinkTypeManager = ComponentAccessor.getComponent(IssueLinkTypeManager)
def allLinkTypes = issueLinkTypeManager.getIssueLinkTypes(false)
// Get the outward link names you want
def outwardAllowedLinks = allLinkTypes.findAll { linkType ->
linkType.outward in allowedOutwardTypesNames
}.collectEntries { linkType ->
[(linkType.outward): linkType.outward]
}
// Get the inward link names you want
def inwardAllowedLinks = allLinkTypes.findAll { linkType ->
linkType.inward in allowedInwardTypesNames
}.collectEntries { linkType ->
[(linkType.inward): linkType.inward]
}
// Combine maps of allowed link direction names
def allowedLinks = outwardAllowedLinks + inwardAllowedLinks
log.debug("Allowed Links = $allowedLinks")
// The options for the 'issuelinks-linktype' field have to be set in this structure: [blocks:blocks, relates to:relates to]
// because the html structure of the field uses the actual link direction name as the value property.
Code removed from the very bottom of the script:" linkTypesField.setFieldOptions(allowedLinks)".
Any help getting the code to work would, as always, be greatly appreciated!
Thanks All.