# Assitance, Struggling to get this script to work

**URL:** <https://forum.library.adaptavist.com/t/assitance-struggling-to-get-this-script-to-work/420>\
**Category:** Scripts\
**Tags:** jira, listener\
**Created:** [January 18, 2024, 10:25pm UTC](https://forum.library.adaptavist.com/t/assitance-struggling-to-get-this-script-to-work/420 "2024-01-18T22:25:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sean.mcconnell](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@sean.mcconnell](https://forum.library.adaptavist.com/u/sean.mcconnell)\
**Post date:** [January 18, 2024, 10:25pm UTC](https://forum.library.adaptavist.com/t/assitance-struggling-to-get-this-script-to-work/420/1 "2024-01-18T22:25:35Z")

</div>

This script is to check for Duplicate Ticket with same Summary name that are open. Link the duplciate ticket and close.

```auto
def issueSummary = issue.fields.summary
logger.info('issue summary is : ' + issueSummary)

def jqlSearch = "summary ~ \"${issueSummary}\""

Map<String, Object> searchResult = get('/rest/api/2/search')
        .queryString('jql', jqlSearch)
        .asObject(Map)
        .body 

def issues = (List<Map<String, Object>>) searchResult.issues
def matchingIssues = []
issues.forEach
{ 
    if(it.summary.contains(issueSummary) && it.fields.status.name != "Closed") 
    {
        matchingIssues.add(it.key)
        
logger.info('issues with matching summary : ' + matchingIssues)

matchingIssues.forEach{

    // Specify the source issue
    final sourceIssueKey = "TEST-1"
    // Specify the target issue
    final targetIssueKey = "TEST-2"
    // Specify the link type to use
    final linkType = "Relates"
    // Create the issue link between both issues
    def link = post('/rest/api/2/issueLink')
        .header('Content-Type', 'application/json')
        .body([
       type: [name: linkType],
       outwardIssue: [key: sourceIssueKey], // This is the issue that the link 'starts' at.
       inwardIssue: [key: targetIssueKey] // This is the issue that the link 'finishes' at.
   ])
   .asString()
// Validate the link was created correctly
(link.status == 201) ? "Success - The issues with the key of ${sourceIssueKey} and ${targetIssueKey} have been linked with the '${linkType}' link type." : "${link.status}: ${link.body}"
}
}
}

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/adaptavistlibrary/original/1X/ceb18adf14fa58b4c6de03aa69ada8b07359620c.png) [@system](https://forum.library.adaptavist.com/u/system)\
**Post date:** [July 16, 2024, 10:26pm UTC](https://forum.library.adaptavist.com/t/assitance-struggling-to-get-this-script-to-work/420/2 "2024-07-16T22:26:24Z")

</div>

Closed on July 16, 2024, 10:26pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
