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.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.