Hi ,I'm writing the script to remove the clone links for an issue in the same project.It seems script complied with no errors but the clones issue links are not removing.can you please suggests.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.user.ApplicationUser
ApplicationUser currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
for(IssueLink link: ComponentAccessor.getIssueLinkManager().getIssueLinks(issue.getId())){
if(link.getIssueLinkType().getName().equals("Clones"))
ComponentAccessor.issueLinkManager.removeIssueLinks(issue, currentUser)
}
Hi @srinivas kattla ,
first of all - please check the name of the link in administration - "Clones" is probably wrong and you have to replace it with "Cloners"
Method removeIssueLinks will remove all the links, not only the one for clone, so probably you should use removeIssueLink instead.
I would recommend you to add some debug code to be able to find out, if you are getting any issue links at all.
Also method getIssueLinks expects to get link type id (not issue id), so I would recommend you to replace it.
Where did you put your code? Is this a post function in your workflow?
Code below works for me, but I'm not sure, if it will be good enough for your use case, maybe some more modifications will be needed.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.user.ApplicationUser
ApplicationUser loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager()
issueLinkManager.getInwardLinks(issue.getId()).each {issueLink ->
if (issueLink.getIssueLinkType().getName().equals("Cloners")) {
issueLinkManager.removeIssueLink(issueLink, loggedInUser)
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Hana Kučerová , Thanks for your input. I will test it and updates as per the need. I'm adding this in post function.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Hana Kučerová : I was able to work it out for issuelink type cloners but for other issuelinktype the script is not working .Can you please suggest
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.user.ApplicationUser
ApplicationUser loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager()
issueLinkManager.getInwardLinks(issue.getId()).each {issueLink ->
if (issueLink.getIssueLinkType().getName().equals("System Test Execution") && issue.issueType.name == 'Story'){
issueLinkManager.removeIssueLink(issueLink, loggedInUser)
}
}
issueLinkManager.getOutwardLinks(issue.getId()).each {issueLink ->
if (issueLink.getIssueLinkType().getName().equals("System Test Execution") && issue.issueType.name == 'Story'){
issueLinkManager.removeIssueLink(issueLink, loggedInUser)
}
}
issueLinkManager.getInwardLinks(issue.getId()).each {issueLink ->
if (issueLink.getIssueLinkType().getName().contains("Test") && issue.issueType.name == 'Story'){
issueLinkManager.removeIssueLink(issueLink, loggedInUser)
}
}
issueLinkManager.getOutwardLinks(issue.getId()).each {issueLink ->
if (issueLink.getIssueLinkType().getName().contains("Test") && issue.issueType.name == 'Story'){
issueLinkManager.removeIssueLink(issueLink, loggedInUser)
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @srinivas kattla ,
it seems to me, that the script should work. Did you try it without the condition
issue.issueType.name == 'Story'
, i. e. for all types of issues?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried this but it is removing all issue.links for issuelink type. This should not happen .It should only remove the destination issuelinke type story which is linked. please suggest
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @srinivas kattla ,
so, you are trying to remove all the issue links, which meet two requirements:
Am I right?
If so, please try this:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.user.ApplicationUser
final ISSUE_LINK_NAMES = [
"System Test Execution",
"Test",
]
final ISSUE_TYPE_NAME = "Story"
ApplicationUser loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager()
issueLinkManager.getInwardLinks(issue.getId()).each {issueLink ->
String linkedIssueType = issueLink.getSourceObject().getIssueType().getName()
String issueLinkName = issueLink.getIssueLinkType().getName()
if (ISSUE_LINK_NAMES.contains(issueLinkName) && linkedIssueType == ISSUE_TYPE_NAME) {
issueLinkManager.removeIssueLink(issueLink, loggedInUser)
}
}
issueLinkManager.getOutwardLinks(issue.getId()).each {issueLink ->
String linkedIssueType = issueLink.getDestinationObject().getIssueType().getName()
String issueLinkName = issueLink.getIssueLinkType().getName()
if (ISSUE_LINK_NAMES.contains(issueLinkName) && linkedIssueType == ISSUE_TYPE_NAME) {
issueLinkManager.removeIssueLink(issueLink, loggedInUser)
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Hana Kučerová ,
i added this script in Create Workflow with "Custom script post-function". and put it in the last step.
when i create an issue from Clone, "Clone From" link cannot be removed in the new created issue.
Could you please give me some suggestions?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
i updated the scripts and move it to Listener, now it works.
more reference here,
1. in post function,
issueLinkManager.getOutwardLinks(issue.getId())
always returns [].
2. but after the issue is created, i execute the same command in Scriptrunner ->console, it works.
3. so i guess maybe there are something wrong in timing sequence. but even i add 30 seconds to wait before the command is execute, it still cannot work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.