# Script Listener - Migrate to cloud

**URL:** <https://forum.library.adaptavist.com/t/script-listener-migrate-to-cloud/484>\
**Category:** ScriptRunner\
**Tags:** cloud, jira\
**Created:** [July 18, 2024, 10:09am UTC](https://forum.library.adaptavist.com/t/script-listener-migrate-to-cloud/484 "2024-07-18T10:09:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![swathi](https://avatars.discourse-cdn.com/v4/letter/s/35a633/32.png) [@swathi](https://forum.library.adaptavist.com/u/swathi)\
**Post date:** [July 18, 2024, 10:09am UTC](https://forum.library.adaptavist.com/t/script-listener-migrate-to-cloud/484/1 "2024-07-18T10:09:59Z")

</div>

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 :

```auto
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

---

<div class="post-metadata">

**Author:** ![schua](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.library.adaptavist.com/schua/32/177_2.png) [@schua](https://forum.library.adaptavist.com/u/schua)\
**Post date:** [July 23, 2024, 10:57am UTC](https://forum.library.adaptavist.com/t/script-listener-migrate-to-cloud/484/2 "2024-07-23T10:57:04Z")

</div>

Hi Swathi,  
Hope you are doing well. With Cloud, you need to work with [Jira Cloud REST API](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#version) to make this Listener work.

Sharing some samples from our Adaptavist Library for how it could look in Cloud.

- [Add or Update the Issue Link for an Issue in Jira Cloud](https://library.adaptavist.com/entity/basics-updating-issue-links-cloud?tab=cloud)
- [Create a linked development Bug when a Bug raised in a service management project.](https://library.adaptavist.com/entity/create-linked-development-bug?tab=cloud)

You can likely define the constants along these lines;

def PATTERN = /(?:\s|^||)(DM-[0-9]+)/  
def issueKey = issue.key  
def issuetype = issue.fields.issuetype.name  
def description = issue.fields.description

And then have something like…

if (issuetype == “Epic” && description) {  
def matcher = description =~ PATTERN  
while (matcher.find()) {  
def matchedIssueKey = matcher.group(1).trim().toUpperCase()

or something…I’m not sure of the full process which you want to do, feel free to drop an email to [customersuccess@scriptrunnerhq.com](mailto:customersuccess@scriptrunnerhq.com) for one of us CSM’s to take a look with you, or you can open a [support ticket](https://the-adaptavist-group-support.atlassian.net/servicedesk/customer/portals) with our Support Engineers to help on the more technical end.

Regards,  
Sean
