Hi folks,
I have three request types in a JSM project, let's say:
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
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:-
Please ensure that when configuring the Behaviour, it is mapped to the JSM / Service Desk project as shown in the screenshot below:-
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 Support, Product trial questions, and Report a bug, as shown in the screenshot below:-
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:-
If the Product trial questions request type is selected, the list is filtered to only Option 3, as shown in the screenshot below:-
And finally, if the Report a bug request type is selected, the list is filtered to Option 4, as shown in the screenshot below:-
I hope this helps to answer your question. :-)
Thank you and Kind regards,
Ram
@Ram Kumar Aravindakshan _Adaptavist_you saved my day. Everything works like a charm!
I can't express enough gratitude for your effort.
-Albert
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.