Scriptrunner: getting the Request Type value

Deleted user April 13, 2017

I'm having some issues getting the request type value on issues. The string I get back is similar to:

bap/df17bef0-04d3-43d2-be22-f393f6a3e655

 

I assume I need to feed that to some methode from the Service Desk API to get a usable string. Has anyone found a solution for this?

5 answers

1 accepted

3 votes
Answer accepted
Deleted user June 29, 2018
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.servicedesk.api.requesttype.RequestTypeService
import com.onresolve.scriptrunner.runner.customisers.WithPlugin

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

@WithPlugin("com.atlassian.servicedesk")
def requestTypeService = ComponentAccessor.getOSGiComponentInstanceOfType(RequestTypeService)
def reqQ = requestTypeService.newQueryBuilder().issue(issue.id).build()
def reqT = requestTypeService.getRequestTypes(currentUser, reqQ)
def requestType = reqT.right.results[0].getName()
Sergio Palacio August 17, 2018

Hi @Justin 

I'm using your code to create a validation.  

The user select the "Alpha" service but the get load "Beta" service.

...
@WithPlugin("com.atlassian.servicedesk")
RequestTypeService requestTypeService = ScriptRunnerImpl.getPluginComponent(RequestTypeService)

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def reqQ = requestTypeService.newQueryBuilder().issue(issue.id).build()
def reqT = requestTypeService.getRequestTypes(currentUser, reqQ)
def requestTypeName = reqT.right.results[0].getName()
log.warn("REQUEST TYPE" + requestTypeName)

 

if (requestTypeName == "Alpha"){
blah
}

the log warn shows

WARN [jira.groovy]: REQUEST TYPE Beta



Serhii Riabovil August 23, 2018

Hi @Sergio Palacio

I have a similar problem with a validator on issue creation

def reqQ = requestTypeService.newQueryBuilder().issue(issue.id).build()

issue.id is null before issue is actually created, so the code above doesn't work correctly

 

I've only managed to get requestType with the deprecated method:

RequestType requestType = requestTypeService.getRequestTypeForIssue(currentUser, issue).right().get()

 

Nicolas Esteves September 4, 2019

Hi,

With most recent JSD versions, the right() method is no longer needed:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.servicedesk.api.requesttype.RequestTypeService
import com.onresolve.scriptrunner.runner.customisers.WithPlugin

@WithPlugin("com.atlassian.servicedesk")

def issueManager = ComponentAccessor.getIssueManager()
def issue = issueManager.getIssueObject("TEST-1")
def requestTypeService = ComponentAccessor.getOSGiComponentInstanceOfType(RequestTypeService)
def userManager = ComponentAccessor.getUserManager()
def robotUser = userManager.getUserByName("robot")

def reqQ = requestTypeService.newQueryBuilder().issue(issue.id).build()
def reqT = requestTypeService.getRequestTypes(robotUser, reqQ)
def requestTypeName = reqT.getResults()[0].getName()

return requestTypeName

Nicolas

Like # people like this
2 votes
JamieA
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.
April 18, 2017

How are you getting that?

Using the following code:

def customFieldManager = ComponentAccessor.customFieldManager
def customField = customFieldManager.getCustomFieldObjectByName("Customer Request Type")
log.debug(issue.getCustomFieldValue(customField))


I get "srjsup/get-it-help"

The format of this is portalId / request-type-key.

I've dug around to try to get the proper display name, but service desk is half-written in scala, and it doesn't decompile nicely.

 

Deleted user April 18, 2017

Thats pretty much what I had been doing and was receivng that ID back instead of the name. I finally got this solved with the below code. My biggest issue with it is using a deprecated methode in getRequestTypeForIssue. I can't seem to figure out the newer methodes using a query builder, can't find any helpful examples either.

https://docs.atlassian.com/jira-servicedesk/server/com/atlassian/servicedesk/api/requesttype/RequestTypeQuery.Builder.html

https://docs.atlassian.com/jira-servicedesk/server/com/atlassian/servicedesk/api/requesttype/RequestTypeQuery.html

https://docs.atlassian.com/jira-servicedesk/server/com/atlassian/servicedesk/api/requesttype/RequestTypeService.html#getRequestTypes-com.atlassian.jira.user.ApplicationUser-com.atlassian.servicedesk.api.requesttype.RequestTypeQuery-

 

import com.atlassian.servicedesk.api.requesttype.RequestTypeService
import com.atlassian.servicedesk.api.requesttype.RequestType
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin

@WithPlugin("com.atlassian.servicedesk")

@PluginModule

RequestTypeService requestTypeService

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

RequestType getRequestType = requestTypeService.getRequestTypeForIssue(currentUser, issue).right().get()
String requestTypeName = getRequestType.getName()

 

 

 

 

 

Nicolas Esteves November 30, 2017

Wow thank you Justin, that's what I wanted! :)

Deleted user January 30, 2018

Your welcome, happy it was helpful!

1 vote
kilinich May 10, 2018

Hi, Justin. Did you manage to find out how to use query builder to get request names by id?

Deleted user May 10, 2018

I did :)

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.servicedesk.api.requesttype.RequestTypeService
import com.onresolve.scriptrunner.runner.customisers.WithPlugin

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

@WithPlugin("com.atlassian.servicedesk")
def requestTypeService = ComponentAccessor.getOSGiComponentInstanceOfType(RequestTypeService)
def reqQ = requestTypeService.newQueryBuilder().issue(issue.id).build()
def reqT = requestTypeService.getRequestTypes(currentUser, reqQ)
def requestType = reqT.right.results[0].getName()

 

Like David Harkins likes this
kilinich May 10, 2018

Oh, Thank you, thank you, thank you.

I was close, but not succeed to solve that puzzle /-) 
Great, now I can move futher!

Giancarlo Bisceglia
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 13, 2018

works thanks !!

0 votes
Philip Kasapov October 14, 2021

Hi,

 

What is the proper way of retrieving the request type icon url? RequesType has a method .getIconId() which returns the id of the icon but what next? How can we retrieve the url to this icon? 

Thank you,

Philip

0 votes
René Rondón August 5, 2019

Hello.

How or where can I use that string? I'm a novice Jira user who is still getting the same error: request type id onstead of request type name.

I would appreciate your answer.

Kind regards.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events