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.ComponentAccessorimport com.atlassian.jira.issue.Issueimport com.atlassian.jira.user.ApplicationUserimport com.atlassian.servicedesk.api.requesttype.RequestTypeimport com.atlassian.servicedesk.api.requesttype.RequestTypeQueryimport com.atlassian.servicedesk.api.requesttype.RequestTypeServiceimport com.atlassian.servicedesk.api.util.paging.PagedResponseimport com.onresolve.scriptrunner.runner.customisers.WithPlugin@WithPlugin("com.atlassian.servicedesk")String requestTypeName = getRequestTypeName(issue)String scriptFieldResultswitch (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 scriptFieldResultstatic 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.
It looks like you're new here. Sign in or register to get started.