Hello,
I would like to display only some options in 'Linked Issue' field when user tries to add link to an issue.
I tried to create an intialiser behaviour but it is not working, still all of the options are displayed.
this is my script:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLinkTypeManager
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
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)
FormField links = getFieldById("issuelinks-linktype")
def allowedOutwardTypes = ["blocks", "relates to", "causes"]
def allowedInwardTypes = ["is blocked by", "relates to", "is caused by"]
IssueLinkTypeManager issueLinkTypeManager = ComponentAccessor.getComponent(IssueLinkTypeManager)
//get the outward link names you want
Map outwardAllowedLinks = issueLinkTypeManager.getIssueLinkTypes(false).findAll{ it.outward in allowedOutwardTypes }.collectEntries{
[it.outward,it.outward]
}
//get the inward link names you want
Map inwardAllowedLinks = issueLinkTypeManager.getIssueLinkTypes(false).findAll{ it.inward in allowedInwardTypes }.collectEntries{
[it.inward,it.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. I checked on the software screens, not checked service desk yet.
links.setFieldOptions(allowedLinks)
Can someone help me with it ?
Thanks!