Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

JSM display field options based on the Request Type

Albert Manuel
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.
March 17, 2023

Hi folks,

I have three request types in a JSM project, let's say:

  1. RT1
  2. RT2
  3. RT3

I also have a custom field, single select choice type with 6 options (OPT1, OPT2 etc OPT6).

I'm trying to create a Scriptrunner ->Behaviour script on this custom field so that if someone tries to create a ticket in the portal and they choose the Request Type RT1 to display only options OPT1 and OPT2 for example in the custom field. If they select RT2 to display only OPT3 and OPT4 etc.

Can someone help me with such a script example?

I tried with this thing:

def field = getFieldByName('MyCustomFieldname')
field.setFieldOptions(['OPT1', 'OPT2', 'OPT3'])

Works but for a single request type - how can i add more?

Thanks

 

2 answers

1 accepted

5 votes
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
March 17, 2023

Hi @Albert Manuel

For your requirement, you will need to use the Behaviour Initialiser.

Below is a working sample code for your reference:-

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours behaviours
def sampleList = getFieldByName('Sample List')

def customFieldManager = ComponentAccessor.customFieldManager
def optionManager = ComponentAccessor.optionsManager

def sampleListCustomField = customFieldManager.getCustomFieldObject(sampleList.fieldId)

def availableConfig = sampleListCustomField.getRelevantConfig(issueContext)
def sampleListOptions = optionManager.getOptions(availableConfig)

def availableOptions = []

if (requestTypeName == 'Technical support') {
availableOptions = ['Option 1', 'Option 2']
} else if (requestTypeName == 'Product trial questions') {
availableOptions = ['Option 3']
} else if (requestTypeName == 'Report a bug') {
availableOptions = ['Option 4']
}

def availableOptionsMap = sampleListOptions?.findAll {
it.value in availableOptions
}
sampleList.setFieldOptions(availableOptionsMap)

Please note that the sample code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

Below is a screenshot of the Behaviour configuration:-

behaviour_configuration.png

Please ensure that when configuring the Behaviour, it is mapped to the JSM / Service Desk project as shown in the screenshot below:-

behaviour_mapping.png

Below are a couple of test screenshots for your reference.

For this test case, the Behaviour has been configured for 3 request types, i.e. Technical SupportProduct trial questions, and Report a bug, as shown in the screenshot below:-

behaviour_config2.png

If the Technical Request request type is selected, the list is filtered to the options Option 1 and Option 2 and shown in the screenshot below:-

technical_support.png

If the Product trial questions request type is selected, the list is filtered to only Option 3, as shown in the screenshot below:-

product_trial_questions.png

And finally, if the Report a bug request type is selected, the list is filtered to Option 4, as shown in the screenshot below:-

report_a_bug.png

I hope this helps to answer your question. :-)

Thank you and Kind regards,

Ram

Albert Manuel
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.
March 18, 2023

@Ram Kumar Aravindakshan _Adaptavist_you saved my day. Everything works like a charm!

I can't express enough gratitude for your effort.

-Albert

0 votes
Kai Becker
Community Champion
March 17, 2023

Hi @Albert Manuel

could you please paste a screenshot of the whole behaviour and the rest of your script?

Basically you need to implement a distinction of cases comparing the Customer Request Type.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events