You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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
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()
}
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.