Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,555,308
Community Members
 
Community Events
184
Community Groups

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

Maikes
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Feb 07, 2020

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 ? 

 

Regards

1 answer

1 vote
Alejandro Suárez
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Feb 07, 2020 • edited Feb 08, 2020

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

@WithPlugin("com.atlassian.servicedesk")

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()
.issue(issue.getId())
.build()
PagedResponse<RequestType> pagedResponse = requestTypeService.getRequestTypes(currentUser, requestTypeQuery)
return pagedResponse?.first()?.getName()
}
Alejandro Suárez
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Feb 07, 2020

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
TAGS
AUG Leaders

Atlassian Community Events