Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Limiting Linked Issues Values via ScriptRunner

Myles Megaffin August 20, 2024

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. 

This is my current code: 

 

 

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)

1 answer

1 accepted

0 votes
Answer accepted
Florian Bonniec
Community Champion
August 20, 2024

Hi

 

If you want to limit the links with behaviour when clicking on More > Linking, you cannot. It only works on fields, that do not include Link action.

One way to limit the list value everywhere is to use an app named Extended Scheme for JIRA.

Extended Schemes for Jira | Atlassian Marketplace

Regards

Suggest an answer

Log in or Sign up to answer