Get the Request Type Name in an Issue Event Listener

Overview

This script retrieves the request type name in an event listener.

Example

I need to do something in an "issue created" event listener, depending on the request type name. Note that there is not a one-to-one mapping between issue type name and request type name, so we need to use the following code rather than look it up from the issue type name.

Good to Know

  • As this script is a "snippet", it also can be executed in the Console. In this case, the line def issue = event.issue needs to be removed.

Requirements

Jira Service Desk Jira Service Desk (4.0 - 4.6)

    
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.servicedesk.api.requesttype.RequestTypeService import com.onresolve.scriptrunner.runner.customisers.PluginModule import com.onresolve.scriptrunner.runner.customisers.WithPlugin import com.atlassian.servicedesk.internal.customfields.origin.VpOrigin import com.atlassian.servicedesk.internal.feature.customer.request.requesttype.CachedImmutableRequestTypeImpl @WithPlugin("com.atlassian.servicedesk") @PluginModule RequestTypeService requestTypeService def issue = event.issue def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser def customFieldManager = ComponentAccessor.customFieldManager def requestTypeCustomField = customFieldManager.getCustomFieldObjects(issue).findByName('Customer Request Type') def requestTypeKey = (issue.getCustomFieldValue(requestTypeCustomField) as VpOrigin)?.requestTypeKey if (!requestTypeKey) { return } def query = requestTypeService.newQueryBuilder().issue(issue.id).build() def requestType = requestTypeService.getRequestTypes(currentUser, query).results.find { (it as CachedImmutableRequestTypeImpl).key == requestTypeKey } def requestTypeName = requestType.name // requestTypeName contains the name of the request type requestTypeName
Discovered an issue? Report it here

Suggested for you