I'm trying to limit the values users are allowed to select when linking issues using scriptrunner behaviour. I can limit the Creating and Editing values but I'm not able limit the linking of 2 already existing issues.
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
@BaseScript FieldBehaviours fieldBehaviours
def log = Logger.getLogger(getClass())
log.setLevel(Level.DEBUG)
def linkTypesField = getFieldById("issuelinks-linktype")
def allowedOutwardTypesNames = ["depends on", "is dependent on by", "relates to"]
def allowedInwardTypesNames = ["depends on", "is dependent on by", "relates to"]
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.
linkTypesField.setFieldOptions(allowedLinks)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.