You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
Hi,
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.issue.link.IssueLinkManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.link.*
import com.atlassian.jira.issue.link.RemoteIssueLinkBuilder
import com.atlassian.jira.issue.link.RemoteIssueLink
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.RemoteIssueLinkManager
import com.atlassian.jira.bc.issue.link.RemoteIssueLinkService
////////////////////////////////////////////////////////////////////////////////////////
//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(issue.id)
def parentIssue
def taskIssue
issueLinkManager.getOutwardLinks(issue.id).each {issueLink ->
def M_Issues = "" + issueLink.getDestinationObject()
MutableIssue MObj = ComponentAccessor.getIssueManager().getIssueObject(M_Issues)
def LinkedType = MObj.issueType.name
if (LinkedType == "Milestone") {
issueLinkManager.getOutwardLinks(MObj.id).findAll {fooLink ->
taskIssue = fooLink?.getDestinationObject()
//if(taskIssue.summary== "Requirements"){
if(taskIssue.issueType.name== "Task"){
rilm.getRemoteIssueLinksForIssue(issue).findAll {
it.applicationType == RemoteIssueLink.APPLICATION_TYPE_CONFLUENCE
}.each {
rilm.createRemoteIssueLink(
new RemoteIssueLinkBuilder(it)
.id(null)
.issueId(taskIssue.id)
.build(),
jirauser
)
// }
// }
}
}
}
// }
}
}
I figured it out the code to validate it.
Here it is.
if(taskIssue.issueType.name== "Task"){
rilm.getRemoteIssueLinksForIssue(issue).findAll {
it.applicationType == RemoteIssueLink.APPLICATION_TYPE_CONFLUENCE
}.each {
def builder = new RemoteIssueLinkBuilder(it).id(null).issueId(taskIssue.id);
def remoteIssueLink = builder.build();
def validationResult = remoteIssueLinkService.validateCreate(jirauser,remoteIssueLink);
if(validationResult.isValid()) {
def result = remoteIssueLinkService.create(jirauser, validationResult)
//log.info "result is" + result;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.