Scriptrunner: getting the Request Type value

I'm having some issues getting the request type value on issues. The string I get back is similar to:

bap/df17bef0-04d3-43d2-be22-f393f6a3e655

 

I assume I need to feed that to some methode from the Service Desk API to get a usable string. Has anyone found a solution for this?

1 answer

How are you getting that?

Using the following code:

def customFieldManager = ComponentAccessor.customFieldManager
def customField = customFieldManager.getCustomFieldObjectByName("Customer Request Type")
log.debug(issue.getCustomFieldValue(customField))


I get "srjsup/get-it-help"

The format of this is portalId / request-type-key.

I've dug around to try to get the proper display name, but service desk is half-written in scala, and it doesn't decompile nicely.

 

Thats pretty much what I had been doing and was receivng that ID back instead of the name. I finally got this solved with the below code. My biggest issue with it is using a deprecated methode in getRequestTypeForIssue. I can't seem to figure out the newer methodes using a query builder, can't find any helpful examples either.

https://docs.atlassian.com/jira-servicedesk/server/com/atlassian/servicedesk/api/requesttype/RequestTypeQuery.Builder.html

https://docs.atlassian.com/jira-servicedesk/server/com/atlassian/servicedesk/api/requesttype/RequestTypeQuery.html

https://docs.atlassian.com/jira-servicedesk/server/com/atlassian/servicedesk/api/requesttype/RequestTypeService.html#getRequestTypes-com.atlassian.jira.user.ApplicationUser-com.atlassian.servicedesk.api.requesttype.RequestTypeQuery-

 

import com.atlassian.servicedesk.api.requesttype.RequestTypeService
import com.atlassian.servicedesk.api.requesttype.RequestType
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin

@WithPlugin("com.atlassian.servicedesk")

@PluginModule

RequestTypeService requestTypeService

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

RequestType getRequestType = requestTypeService.getRequestTypeForIssue(currentUser, issue).right().get()
String requestTypeName = getRequestType.getName()

 

 

 

 

 

Wow thank you Justin, that's what I wanted! :)

Your welcome, happy it was helpful!

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Apr 10, 2018 in Marketplace Apps

Learn about how Stefan K. built one of the *first ever* Marketplace apps

In this post you will discover more about the evolution of K15t software, some big topics they're currently focusing on in the app space, and a rare (not not funny!) photo of founders Mike Cannon-Bro...

13,073 views 11 24
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you