Hi,
I am setting up a behaviour in Scriptrunner and for the most part have everything working what isn't working is the setting of my single select values.
What's happening is that when I set the option values the option of 'None' is not available.
I've striped down my code to remove any conditions and only set the options to see if they were the cause of the problem. It has not made any difference to the outcome.
Bellow is the code I'm currently running. As you can see in the log output that None is missing and is also missing from the drop down.
Did I miss something? Or is this expected?
Any help would be appreciated.
Neil
//Participation Type Field Options
def ParticipationTypeCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_14911");
def ParticipationTypeConfig = ParticipationTypeCF.getRelevantConfig(getIssueContext());
def ParticipationTypeOptions = optionsManager.getOptions(ParticipationTypeConfig);
// Set the values inside the select list field
def ParticipationTypeMap = ParticipationTypeOptions.findAll {
it.value in ["None", "Informal Remarks", "Keynote Address", "Speech", "Report"]
}.collectEntries {
[(it.optionId.toString()): it.value]
}
ParticipationTypeField.setFieldOptions(ParticipationTypeMap);
log.warn("***** ParticipationTypeOptions **** " + ParticipationTypeOptions);
--- Log output ---
018-11-07 10:24:23,197 /rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/runvalidator.json [jira.groovy.user.FieldBehaviours] ***** ParticipationTypeOptions **** [Informal Remarks, Keynote Address, Speech, Report]
Hi Neil,
You might try adding the "None" option back like so:
//Participation Type Field Options
def ParticipationTypeCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_14911");
def ParticipationTypeConfig = ParticipationTypeCF.getRelevantConfig(getIssueContext());
def ParticipationTypeOptions = optionsManager.getOptions(ParticipationTypeConfig);
// Set the values inside the select list field
def ParticipationTypeMap = [null: "None"]
ParticipationTypeMap += ParticipationTypeOptions.findAll {
it.value in ["Informal Remarks", "Keynote Address", "Speech", "Report"]
}.collectEntries {
[(it.optionId.toString()): it.value]
}
ParticipationTypeField.setFieldOptions(ParticipationTypeMap);
log.warn("***** ParticipationTypeOptions **** " + ParticipationTypeOptions);
Regards,
Josh
Hi,
Thanks but unfortunately that doesn't work. It throws an exception that that map doesn't match the expected pattern. It also caused a stack over flow error message.
Neil
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Neil,
What version of ScriptRunner/Jira are you using? This is the exact script I just tested on v5.4.36:
import com.atlassian.jira.component.ComponentAccessor
def optionsManager = ComponentAccessor.getOptionsManager()
def ParticipationTypeField = getFieldByName("SelectListA") // your field name here
//Participation Type Field Options
def ParticipationTypeCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10019"); // your field ID here
def ParticipationTypeConfig = ParticipationTypeCF.getRelevantConfig(getIssueContext());
def ParticipationTypeOptions = optionsManager.getOptions(ParticipationTypeConfig);
// Set the values inside the select list field
def ParticipationTypeMap = [null: "None"]
ParticipationTypeMap += ParticipationTypeOptions.findAll {
it.value in ["Informal Remarks", "Keynote Address", "Speech", "Report", "AAA", "BBB"]
}.collectEntries {
[(it.optionId): it.value]
}
ParticipationTypeField.setFieldOptions(ParticipationTypeMap);
log.warn("***** ParticipationTypeOptions **** " + ParticipationTypeOptions);
This is the map returned:
DEBUG 2018-11-09 08:36:54,313 [onresolve.jira.behaviours.BehaviourManagerImpl] Returning map: [customfield_10019:[fieldOptions:[null=None, 10003=AAA, 10004=BBB], fieldType:com.atlassian.jira.plugin.system.customfieldtypes:select, displayName:SelectListA]]
And here is the field on the screen with the "None" option added back:
Regards,
Josh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What exact type of field is "ParticipationTypeCF"? Is it just a normal Select List custom field?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
The field type is a normal custom field single select list.
We are running:
Script runner Version: 4.1.3.29
Jira server: 6.4.10
Neil
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Neil,
Unfortunately, I don't have access to Jira 6 so I am not able to test the script in your exact environment. There were an incredible number of changes between 4.1.3.29 and the current version.
Perhaps try this:
import com.atlassian.jira.component.ComponentAccessor
def optionsManager = ComponentAccessor.getOptionsManager()
//Participation Type Field Options
def ParticipationTypeField = getFieldById("customfield_14911")
def ParticipationTypeCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_14911");
def ParticipationTypeConfig = ParticipationTypeCF.getRelevantConfig(getIssueContext());
def ParticipationTypeOptions = optionsManager.getOptions(ParticipationTypeConfig);
// Set the values inside the select list field
def ParticipationTypeMap = [:]
ParticipationTypeMap.put("-1", "None")
ParticipationTypeMap += ParticipationTypeOptions.findAll {
it.value in ["Informal Remarks", "Keynote Address", "Speech", "Report"]
}.collectEntries {
[(it.optionId.toString()): it.value]
}
ParticipationTypeField.setFieldOptions(ParticipationTypeMap);
log.warn("***** ParticipationTypeOptions **** " + ParticipationTypeOptions);
I'm thinking that adding "-1" as an option restores the "None" option in your version...
Regards,
Josh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Glad to hear it worked, Neil.
Thx for using ScriptRunner!
Regards,
Josh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Joshua Yamdogo @ Adaptavist and @Neil Dixon ,
I tried the same script but is returning an error on the last line as: Cannot find matching method
Could you please help and let me know how to resolve the same.
Thanks and Regards,
Swapnil Srivastav
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Neil Dixon and Joshua Yamdogo @ Adaptavist
I tried the code but it is not working for me. No options are displayed on the screen.
Could you please help.
Thanks and Regards,
Swapnil Srivastav.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
We still run the above code on our systems without any issue.
If you could post the code your running? It maybe that something was missed.
If you dump your options to the log what are you seeing?
Thanks,
Neil
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
HI
Can you please suggest how to set one value from various options in the screen selectbox using behaviour.
Regards
Shradha
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.