Restrict available issue options for Linked Issues

Marko Dev June 19, 2023

Greetings community,

Is there a possibility to limit the user on which issue type they can select for linking issues (Linked Issue) in Jira by using ScriptRunner?

For example, if I want to link an Issue of type Story, I want to restrict the users only to be able to link the Story Issue to a Task Issuetype.

I am working on Jira Software for Data Center.

Thank you!

2 answers

1 accepted

0 votes
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 20, 2023

Hi @Marko Dev

Welcome to the Community.

For your requirement, using the Server-Side Behaviour for the Linked Issues field would be best.

Below is a working sample code for your reference:-

import com.adaptavist.hapi.jira.issues.Issues
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours
def linkedIssues = getFieldById(fieldChanged)
def issueLinksIssue = getFieldById("issuelinks-issues")

linkedIssues.clearError()

if (linkedIssues && issueContext.issueType.name == 'Story' && issueLinksIssue.formValue) {
def issueKey = issueLinksIssue.formValue as String
if (Issues.getByKey(issueKey).issueType.name != 'Task') {
linkedIssues.setError('Only Task Types can be selected')
}
}

Please note that the sample code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

Also please note that in this code I have used a feature from ScriptRunner's HAPI feature. To be able to use this feature, please ensure that you upgrade your ScriptRunner plugin to the latest release, i.e. 8.4.0.

Below is a screenshot of the Behaviour configuration:-

behaviour_config.png

What this script does is that when the issue is either being created/edited or in a transition, it checks on the linked issue type that is selected.

In this case, if the current issue type created or updated is a Story unless the Linked Issue Type selected is Task, it will return an error message.

I hope this helps to answer your question. :-)

Thank you, and Kind regards,

Ram

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 8, 2023

Hi @Marko Dev

Has your question been answered?

If yes, please accept the answer provided.

Thank you and Kind regards,

Ram

Samuel Stephens
Contributor
October 12, 2023

Hi @ram 

I note this option does not limit the links available using the link issue option from the ops bar. Your example only limits issues based on the create/update function.

Is there a way to achieve this for the screen shown during issue link from the ops-bar?

Thanks,

Sam

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 13, 2023

Hi @Samuel Stephens

In your comment, you asked:-

I note this option does not limit the links available using the link issue option from the ops bar. Your example only limits issues based on the create/update function.

Is there a way to achieve this for the screen shown during issue link from the ops-bar?

Could you please clarify what you mean by this? Are you referring to using an obs-bar link to open a create issue dialog?

If yes then it is possible, i.e. when the dialog opens, you can use the Behaviour to trigger when that dialog opens.  Otherwise if you want it to work like a transition, then Behaviour may not be the best approach.

Thank you and Kind regards,

Ram

Samuel Stephens
Contributor
October 13, 2023

Hi @Ram Kumar Aravindakshan _Adaptavist_ 

Close, I’m referring to the ops-bar drop down specifically More > Link

This option allows me to link the current issue to other issues by providing the link type and the issue I want to link.

I want to limit the list of available linkages. However I can’t seem to find anywhere to do it outside of a Create/Edit screen or as a Validator on a transition.

Hopefully we can solve this! :)

Gianni Pucciani
Contributor
May 29, 2024

I am also looking for a solution to this problem, in the Server instance we used to have a Link Schemes plugin. But on Cloud there does not seem to be a "simple" solution. 

When a user creates a link, I'd like to restrict the choices of available links based on the issue type, so that our object model can be enforced.

0 votes
Harsh Gurnani
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 2, 2024

@Gianni Pucciani  @Samuel Stephens  

I am also looking for this solution, have you guys found it?

Gianni Pucciani
Contributor
July 5, 2024

@Harsh Gurnani   Unfortunately not yet

Suggest an answer

Log in or Sign up to answer