Hi Team,
I want to show/hide fields based on the Group(request type) selected in the portal
but couldn't find a way
I tried pre-set value and hidden the field in jira request type configuration. that sets the value perfectly in issue creation. but unable to fetch the hidden field in behaviour script
and lead or suggestion would be much appreciated
Thanks in advance,
Leo
Hey Leo
Behaviours only gives you the request type name with getRequestTypeName()
There may be a simpler way ... but the only way I know how to get the full request type object (which includes a getGroups method) from it's name is to pull a couple of services and managers and string them together like this:
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.atlassian.servicedesk.api.ServiceDeskManager
import com.atlassian.servicedesk.api.requesttype.RequestTypeService
@WithPlugin("com.atlassian.servicedesk")
@PluginModule ServiceDeskManager serviceDeskManager
@PluginModule RequestTypeService requestTypeService
def serviceDesk = serviceDeskManager.getServiceDeskForProject(issueContext.projectObject)
def queryBuilder = requestTypeService.newQueryBuilder()
queryBuilder.requestOverrideSecurity(true)
queryBuilder.serviceDesk(serviceDesk.id)
def allRequestTyps = requestTypeService.getRequestTypes(null, queryBuilder.build())
def requestType = allRequestTyps.find {
it.name == getRequestTypeName()
}
def groupNames = requestType.groups*.name
Thanks for your quick reply, I get below error hope you can assist me
I have SR 6.19.0 version and JSD 4.5.9, if that matters
Thanks in advance,
Leo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Static type checking errors are not always indicators of bad code. Just that the scriptrunner script editor can't confirm if the code is good or not.
In this case, the "requestTypeService.getRequestTypes" returns a "PagedResponse" object that could contain different kind of items. So the code checker can't know we expect RequestType scpecifically without telling it.
Groovy is dynamic by design and objects can be of varying types.
But if you really want to eliminate these sorts of errors, we can tell the editor what type of object we're deling with.
Add this import :
import com.atlassian.servicedesk.api.requesttype.RequestType
Then replace the last block with
def allRequestTypes = requestTypeService.getRequestTypes(null, queryBuilder.build())
def requestType = allRequestTypes.find {RequestType requestType->
requestType.name == 'Incident'
} as RequestType
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Peter-Dave Sheehan ,
This works awesome, but the problem is it returns all the groups requestType is involved
I want just one group through which customer has selected the request type
e.g. Group 1 --> INC
Group 2 --> INC
If I opened INC through Group 1. I need the result just "Group 1" but the result is both 1 & 2 :(
Thanks,
Leo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I don't think that's knowable.
If you examine the URL when you access the form from one group or another, you will see they are identical.
If that's a critical requirement, you will have to duplicate the request type and have each request type in a single group.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks @Peter-Dave Sheehan
for your time and wonderful assistance :)
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.