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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

Leo Community Leader Mar 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

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 Mar 29, 2021 • edited

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

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 Mar 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

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 Mar 29, 2021

Thanks @Peter-Dave Sheehan

for your time and wonderful assistance :) 

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Service Management

Announcing Mindville Insight is now part of Jira Service Management!

Hello Community! We’re excited to announce that Mindville Insight’s asset and configuration management capabilities will now be integrated into Jira Service Management Premium and Enterprise plan...

594 views 9 14
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you