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!?
Our code:-
Hi Florian, there is no error. The script apparently runs successfully, but it just doesn't do as requested. i.e It DOES NOT restrict the use of Link relationships!?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Before continuing investigating, are you speaking about More > Link or the Linked Issue field ?
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.
Did you set the script as Initialiser and set the proper Mapping to enable the Behaviour on it ?
This one works for me
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 linkTypes = getFieldById("issuelinks-linktype")
def allowedOutwardTypes = ["contains"]
def allowedInwardTypes = ["is contained in"]
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]
}
def allowedLinks = outwardAllowedLinks << inwardAllowedLinks
log.debug("Allowed Links = $allowedLinks")
linkTypes.setFieldOptions(allowedLinks)
Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, I think so. However, my Script Checker still has a problem with the last line of code, as before!?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It should only be a warning no ? It's because we did not use type for the list. It should not impact runtime.
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.
Type error so it should not be the cause as despite the fact that we did not specify it, we are using the right one. I also have this error on my side. Could you share the entire configuration of the behaviour and hide if require sensitive information ?
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.
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.
You should not add the script in link field, you should add it on the Initialiser section, Create Script and paste it there.
By doing so the script will be call when the screen open. If you let it in linked issue field, it only trigger when you update the field.
Regards
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.