How can i Restrict issue link create for current project

I am trying to Restrict issue link create only for current project

Many thanks in advance.

3 answers

1 accepted

1 vote
Answer accepted

Hi,

You can use ScriptRunner Listener to delete link if linked issue is not from current project.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.event.issue.link.IssueLinkCreatedEvent

def issueLinkManager = ComponentAccessor.getIssueLinkManager()
Issue currentIssue = event.getIssueLink().getSourceObject()
def currentProject = currentIssue.projectObject.name
def linkedIssue
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

issueLinkManager.getOutwardLinks(currentIssue.id).each { issueLink ->

     linkedIssue = issueLink.destinationObject

    if( linkedIssue.projectObject.name != currentProject )
{
   
    issueLinkManager.removeIssueLink(issueLink, user)
}
    
}

thanks,i want to write this code in listener and i have this error

unable to resole class "import com.atlassian.jira.event.issue.link.IssueLinkCreatedEvent"

Did you used IssueLinkeCreatedEvent? I have to some errors, but listener work good.

obraz.png

Like 1 person likes this

i try this code and don't have any error but i have error in executelinkscript.png

What version of Jira and Script Runner you have? Can you past here error?

jira version 7.1.4 linkscript2.png

Unfortunately Issue Linked Event was add in Jira 7.5.

Like 1 person likes this

i resolved my problem with this code,thank you for your help

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.project.Project;
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.event.issue.EventUtils

Issue issuesou=event.issue;

def issueLinkManager = ComponentAccessor.getIssueLinkManager()

Issue currentIssue = issuesou
def currentIssueId = issuesou.getId()
def currentProject = currentIssue.projectObject.name
def linkedIssue = issuesou
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

issueLinkManager.getOutwardLinks(currentIssueId).each { issueLink ->

linkedIssue = issueLink.getDestinationObject()

if(linkedIssue.projectObject.name != currentProject )
{

issueLinkManager.removeIssueLink(issueLink, user)
}

}

i resolved my problem with this code,thank you for your help

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.project.Project;
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.event.issue.EventUtils

Issue issuesou=event.issue;

def issueLinkManager = ComponentAccessor.getIssueLinkManager()

Issue currentIssue = issuesou
def currentIssueId = issuesou.getId()
def currentProject = currentIssue.projectObject.name
def linkedIssue = issuesou
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

issueLinkManager.getOutwardLinks(currentIssueId).each { issueLink ->

linkedIssue = issueLink.getDestinationObject()

if(linkedIssue.projectObject.name != currentProject )
{

issueLinkManager.removeIssueLink(issueLink, user)
}

}

i want to my users cant link issue to another project and just can link to current issue project

Hi @reza azad,

Welcome to the community. 

You can do this by editing the permission scheme for your project (You must be an Administrator to do that). You should make sure, that the permission scheme is used only in your project, otherwise create a copy, edit that and assign it to your project.

There is a permission for linking issues. If you remove all associated roles, users and groups, nobody can create an issue link anymore.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Thursday in Jira

Updates to jira.atlassian.com give you visibility into what's coming in Jira Server and Data Center

Hello, Community! My name is Gosia and I'm a Product Manager on Jira Server and Data Center here at Atlassian. Since 2002 when we launched our public issue tracker, jira.atlass...

334 views 1 12
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you