Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to get Hidden field value or request type group in Behaviours?

Leo
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 28, 2021

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

1 answer

0 votes
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 29, 2021

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
Leo
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 29, 2021

Hi @Peter-Dave Sheehan,

Thanks for your quick reply, I get below error hope you can assist me

 image.png

I have SR 6.19.0 version and JSD 4.5.9, if that matters

 

Thanks in advance,

Leo

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 29, 2021

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
Leo
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 29, 2021

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

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 29, 2021

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.

Leo
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 29, 2021

Thanks @Peter-Dave Sheehan

for your time and wonderful assistance :) 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events