Hi Team,
We are trying to migrate script listener from DC to cloud. We have a listener which will check the description of an “Epic”. If it contains an issue key of some pattern, for example CR-■■■, it will automatically add issue link between the current issue(epic) and CR-■■■ issue. Here is the working code for DC :
import com.atlassian.jira.component.ComponentAccessor
def applicationUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def LINKID = 10000 // Clone link type, Change this if you want different link type
def SEQUENCE = 10001 // Don't change the default value
//def PATTERN = /(?:\s|^|\|)([crCR]+-[0-9]+)(?=\s|$|\|\.)/
def PATTERN = /(?:\s|^|\|)([crCR]+-[0-9]+)/
def issue = event.issue
String desc = issue.description
log.warn('Description: ' + desc)
def issuetype = issue.getIssueType().getName()
log.warn('Issue Type: ' + issuetype)
if (issuetype == "Epic") {
def matcher = desc =~ PATTERN
//??Add this to limit execution for changes to Description field only?
//if(event?.getChangeLog()?.getRelated('ChildChangeItem').find {it.field == 'description'}) {
while(matcher.find()) {
def destIssue
log.warn('Match Group 0: ' + matcher.group(0))
log.warn('Match Group 1: ' + matcher.group(1))
try{
destIssue = ComponentAccessor.getIssueManager().getIssueByCurrentKey(matcher.group(1).trim().toUpperCase())
log.warn('Dest: ' + destIssue)
ComponentAccessor.getIssueLinkManager().createIssueLink(issue.id, destIssue.id, LINKID, SEQUENCE, applicationUser)
} catch(Exception ex) {
log.warn("Error linking the issue." + Exception + ex)
}
}
}
We are looking to achieve the same functionality in cloud. Any help is much appreciated.
Thanks,
Swathi