Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How Do I Using Adaptavist ScriptRunner could remove all linked issues and then add one?

Aleksey Dzyapko October 9, 2017 edited

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.

 

 

2 answers

1 accepted

0 votes
Answer accepted
Joshua Yamdogo @ Adaptavist
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 9, 2017

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.

0 votes
Pawel Ogrodnik November 13, 2019

Hi, How to delete only one type of links or all without Sub-Task?

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, confluence, loom, atlassian intelligence, ai notes, ai-powered meeting notes, atlassian community events, ace, confluence ai, loom ai integration, ai note-taking, atlassian ai features, team '25, atlassian live learning, confluence automation

Unlock AI-powered meeting notes: Join our live learning session! 📹

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!
AUG Leaders

Atlassian Community Events