Could someone advise please, how could I delete all linked issue when I change a value of custom filed (for ex. SOW) and then add linked issue mentioned in that field?
I've tried that code, but it doesn't work at all:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import groovy.transform.BaseScript
import groovy.transform.Field
@BaseScript FieldBehaviours fieldBehaviours
MutableIssue currentIssue = issue
@Field
String SOW_CF_ID = 'customfield_21900'
FormField sow = getFieldById(SOW_CF_ID)
ApplicationUser currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
if (sow.value) {
ComponentAccessor.issueLinkManager.removeIssueLinks(issue, currentUser)
}
First of all, because jira doesn't understand what issue it is.
Hello Aleksey,
The problem with your script is that you need to get the underlyingIssue (not just issue) in order to use this in a behaviour. Also, removeIssueLinks() does not accept a MutableIssue as a parameter, so you shouldn't define currentIssue as a MutableIssue.
This is the script that worked for me to remove linked issues:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import groovy.transform.BaseScript
import groovy.transform.Field
@BaseScript FieldBehaviours fieldBehaviours
def currentIssue = underlyingIssue
@Field
String SOW_CF_ID = 'customfield_21900'
FormField sow = getFieldById(SOW_CF_ID)
ApplicationUser currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
if (sow.value) {
ComponentAccessor.issueLinkManager.removeIssueLinks(issue, currentUser)
}
I would also say that I really do not think this should be done in a behaviour. A script listener would be a better fit for this use-case. You could set up a listener that fires on an Issue Updated event. If someone changes the custom field, the listener will delete all issue links once the change to the custom field is made.
Hi, How to delete only one type of links or all without Sub-Task?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Did you catch the news at Team ‘25? With Loom, Confluence, Atlassian Intelligence, & even Jira 👀, you won’t have to worry about taking meeting notes again… unless you want to. Join us to explore the beta & discover a new way to boost meeting productivity.
Register today!Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.