Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
badges earned

Your Points Tracker
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to get a Jira Service Desk Request name in script runner, script fields ?

Hi Dear Colleagues from Atlassian, 

I want to get the request type name to compare in a [Switch Case] in Script Runner Fields. 

Do someaone knows how to help me ? 



1 answer

Hi @Maikes 

I guess that what you need is to get the name of the request type instead of his key (the value you got from getCustomFieldValue())

So here you go:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.servicedesk.api.requesttype.RequestType
import com.atlassian.servicedesk.api.requesttype.RequestTypeQuery
import com.atlassian.servicedesk.api.requesttype.RequestTypeService
import com.atlassian.servicedesk.api.util.paging.PagedResponse
import com.onresolve.scriptrunner.runner.customisers.WithPlugin


String requestTypeName = getRequestTypeName(issue)
String scriptFieldResult

switch (requestTypeName) {
case "RequestTypeName1": scriptFieldResult = "Whatever I want to show on this request type"; break
case "RequestTypeName2": scriptFieldResult = "Whatever I want to show on this request type"; break
default: scriptFieldResult = "Whatever I want to show if i dont find any request type with the previous names"
return scriptFieldResult

static String getRequestTypeName(Issue issue) {
RequestTypeService requestTypeService = ComponentAccessor.getOSGiComponentInstanceOfType(RequestTypeService)
ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
RequestTypeQuery requestTypeQuery = requestTypeService.newQueryBuilder()
PagedResponse<RequestType> pagedResponse = requestTypeService.getRequestTypes(currentUser, requestTypeQuery)
return pagedResponse?.first()?.getName()

Forgot to tell I'm assuming that you have JSD 4.0+ (Jira 8.0+), if you are using 7.X it wont work like that (SD API changes in 8.X).

If that's the case don't worry, I'll give you the correct code.

Suggest an answer

Log in or Sign up to answer
Community showcase

The benefits of using Jira in different departments

Jira is a great tool to use across different departments. Forget that paperwork – switch to Jira and get that tasks done smoothly. Marketing Jira allows for a complete digital transformation of you...

101 views 0 6
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you