Hey everyone,
To say I'm a newbie with ScriptRunner would be an understatement. I needed to find a way to limit the values shown in a drop-down list based on the issue type. I've then managed to find that you're only able to do so via script runner. And here I am.
I've managed to install script runner, find my team-managed project custom field ID, and ran some scripts I found online. As I'm sure this is not a novel request, I'm curious if you know/have a script I can run or if you can spot any issue in the script I'm trying to run-- it's been giving me the below error when I do.
org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: Script1.getFieldById() is applicable for argument types: (String) values: [customfield_12128] at ConsoleScriptExecution1_groovyProxy.run(Unknown Source)
Caused by: groovy.lang.MissingMethodException: No signature of method: Script1.getFieldById() is applicable for argument types: (String) values: [customfield_12128] at Script1.run(Script1.groovy:2) at Script1$run.call(Unknown Source) at Script1$run.call(Unknown Source) at com.adaptavist.sr.cloud.workflow.AbstractScript.evaluate(AbstractScript.groovy:36) at com.adaptavist.sr.cloud.events.ScriptExecution.run(ScriptExecution.groovy:29) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at ConsoleScriptExecution1_groovyProxy.run(Unknown Source) at com.adaptavist.sr.cloud.MainHandler.executeScript(MainHandler.groovy:409) at com.adaptavist.sr.cloud.MainHandler.processInput(MainHandler.groovy:355) at com.adaptavist.sr.cloud.MainHandler.access$0(MainHandler.groovy) at com.adaptavist.sr.cloud.MainHandler$_handleRequest_closure1.doCall(MainHandler.groovy:171) at com.adaptavist.sr.cloud.MainHandler$_handleRequest_closure1.call(MainHandler.groovy)
And this is the code I'm running (copied from: https://community.atlassian.com/t5/Marketplace-Apps-Integrations/Show-some-options-from-a-list-based-on-issue-type/qaq-p/1761285)
int selectListId = 12128
def selectList = getFieldById("customfield_" + selectListId)
String issuetype = getIssueContext().getIssueType().getName()
def map
switch (issuetype) {
case "Production":
map = ["Defect", "RFS", "RFI"]
break;
case "Change Request":
map = ["CR", "Additional Requirement", "Sub-task"]
break;
case "Defect":
map = ["Pre-UAT defect","UAT defect", "SIT defect"]
break;
}
if (map) {
selectList.setFieldOptions(map)
}
Of course, I'll populate my script with relevant details to our org (field id has been correctly adapted) however, I want to see if it passes in the first place.
Any ideas are appreciated!
To answer your question, this is doable. However, the approach you are currently using will not work on Jira Cloud. It is only applicable to Jira Server / DC.
For Cloud, you must make multiple Behaviour configurations if you intend to filter the Select List according to the Issue Type.
Firstly, you will need to gather some information, i.e. the custom field's id, which you appear to have acquired and next, the ids for the custom field values.
1. Edit the Options for the List you intend to filter
2. Move your mouse over the Edit link. You can view the Option's ID as shown in the browser footer in the screenshot below.
You will need to use the information above to filter the option for the select list.
Next, create a Behaviour configuration and set it for a specific issue type.
In the screenshot below, the Behaviour is configured for the Task issue type.
Next, add the script below to the Behaviour configuration:-
getFieldById("customfield_10118").setOptionsVisibility(["10178", "10179"], true)
Below is a screenshot of the Behaviour configuration:-
So the custom field id used in the code above is for the single-select list. In this example, the field I'm using is called Sample List, and the values 10178 and 10179 and the IDs for the options, Option 1 and Option 2 from the Sample List.
Since you intend to add this filter for multiple Issue Types, you must create separate Behaviour configurations for each issue type.
Below is a test screen of the filtered list option when the Task issue type is selected:-
I have created a similar configuration for the Bug issue type and changed the options to Option 3 and Option 4. Below is a screenshot for your reference:-
And for all other Issue Types where the filter is not added, all the options will be displayed as shown in the screenshots below:-
I hope this helps to solve your question. :-)
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.