Add Service Management Ticket Request Participants and Reporter as Watchers on Newly Linked Issues

automateissueuser

Overview

Automate adding service management customers as watchers on newly linked non-service management issues. Use this script as a listener with the IssueLinkCreatedEvent and configure it to listen for events in projects containing linked service management issues. This will auto add service management issue customers as watchers on the non-service desk issues when the non-service desk issue is inward linked to a support desk issue via a specified link type.

Example

I have a support management project and a software development project. I have created a link type named "Cause" with the outward description "caused by" and the inward description "causes". When I link a bug to a support request using the "causes" inward link description, I want to automatically add the support issue customers to the bug as watchers so they will receive notifications when the bug has been fixed.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.event.issue.link.IssueLinkCreatedEvent import com.atlassian.jira.issue.link.IssueLink import com.atlassian.jira.user.ApplicationUser import groovy.transform.Field final requestParticipantsFieldName = 'Request participants' @Field final String LINK_TYPE = 'Cause' def watcherManager = ComponentAccessor.watcherManager def customFieldManager = ComponentAccessor.customFieldManager if (event instanceof IssueLinkCreatedEvent) { def issueLink = (event as IssueLinkCreatedEvent).issueLink if (!isApplicable(issueLink)) { return } def sourceIssue = issueLink.sourceObject // service management issue def destinationIssue = issueLink.destinationObject // core or software issue def requestParticipantsCF = customFieldManager.getCustomFieldObjectsByName(requestParticipantsFieldName).first() def participants = sourceIssue.getCustomFieldValue(requestParticipantsCF) as List List<ApplicationUser> potentialWatchersToAdd = [] potentialWatchersToAdd.add(sourceIssue.reporter) if (participants) { potentialWatchersToAdd.addAll(participants) } potentialWatchersToAdd.each { candidateWatcher -> watcherManager.startWatching(candidateWatcher, destinationIssue.refresh()) } } Boolean isApplicable(IssueLink issueLink) { def service_desk_project_type_key = 'service_desk' def requiredLinkType = issueLink.issueLinkType.name == LINK_TYPE def destinationProjectNotServiceDesk = issueLink.destinationObject.projectObject.projectTypeKey.key != service_desk_project_type_key def sourceProjectIsServiceDesk = issueLink.sourceObject.projectObject.projectTypeKey.key == service_desk_project_type_key def supportIssueHasReporter = issueLink.sourceObject.reporter requiredLinkType && destinationProjectNotServiceDesk && sourceProjectIsServiceDesk && supportIssueHasReporter }