It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How can i Restrict issue link create for current project

reza azad Jan 06, 2019

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

Many thanks in advance.

3 answers

1 accepted

1 vote
Answer accepted
Tomasz Bryła Jan 06, 2019

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)
}
    
}
reza azad Jan 06, 2019

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"

Tomasz Bryła Jan 06, 2019

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

obraz.png

Like reza azad likes this
reza azad Jan 06, 2019

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

Tomasz Bryła Jan 06, 2019 • edited

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

reza azad Jan 06, 2019

jira version 7.1.4 linkscript2.png

Tomasz Bryła Jan 07, 2019

Unfortunately Issue Linked Event was add in Jira 7.5.

Like reza azad likes this
reza azad Jan 08, 2019 • edited

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)
}

}

reza azad Jan 08, 2019

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)
}

}

1 vote
Alexey Matveev [cPrime] Community Leader Jan 06, 2019
reza azad Jan 06, 2019

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

0 votes
Bastian Stehmann [neusta portal services] Community Leader Jan 06, 2019

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
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Next-gen

Introducing subtasks for breaking down work in next-gen projects

Teams break work down in order to help simplify complex tasks. This is often done iteratively, with tasks being broken down into smaller tasks and so on until the work is accurately captured in well-...

920 views 12 15
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you