Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Validation of link and create it


I used following code to create the link to TASK from Project issue type. Its works great but need to validate before create. If already link exist then don't add. Can anyone help me on this.


import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser

import com.atlassian.jira.component.ComponentAccessor
//Used for testing on specific issue
def IssueKey = "TST-4731"  // This is project issue type. linked milestone and task to it. 
def issue = ComponentAccessor.getIssueManager().getIssueObject(IssueKey)
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
// Define Services
CustomFieldManager customFieldManagerObj = ComponentAccessor.getCustomFieldManager()
def jirauser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def rilm = ComponentAccessor.getComponent(RemoteIssueLinkManager)
def remoteIssueLinkService = ComponentAccessor.getComponent(RemoteIssueLinkService)
//Initial Declarations
//Drill up to project ticket for field values

def OutLinkedIssues = issueLinkManager.getOutwardLinks(
def parentIssue
def taskIssue

issueLinkManager.getOutwardLinks( {issueLink ->
def M_Issues = "" + issueLink.getDestinationObject()
MutableIssue MObj = ComponentAccessor.getIssueManager().getIssueObject(M_Issues)

def LinkedType =

if (LinkedType == "Milestone") {
issueLinkManager.getOutwardLinks( {fooLink ->
taskIssue = fooLink?.getDestinationObject()
//if(taskIssue.summary== "Requirements"){
if( "Task"){

rilm.getRemoteIssueLinksForIssue(issue).findAll {
it.applicationType == RemoteIssueLink.APPLICATION_TYPE_CONFLUENCE
}.each {
new RemoteIssueLinkBuilder(it)
// }
// }
// }

1 answer

I figured it out the code to validate it. 


Here it is. 


if( "Task"){

rilm.getRemoteIssueLinksForIssue(issue).findAll {
it.applicationType == RemoteIssueLink.APPLICATION_TYPE_CONFLUENCE
}.each {

def builder = new RemoteIssueLinkBuilder(it).id(null).issueId(;
def remoteIssueLink =;
def validationResult = remoteIssueLinkService.validateCreate(jirauser,remoteIssueLink);

if(validationResult.isValid()) {
def result = remoteIssueLinkService.create(jirauser, validationResult)
// "result is" + result;

Suggest an answer

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

Online AMA this week: Your project management questions answered by Jira Design Lead James Rotanson

We know that great teams require amazing project management chops. It's no surprise that great teams who use Jira have strong project managers, effective workflows, and secrets that bring planning ...

198 views 1 6
Read article

Atlassian Community Events