Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
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

Scriptrunner behaviour - Setting select list options 'None' is not available.

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]

 

1 answer

1 accepted

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

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:

Screen Shot 2018-11-09 at 8.37.03 AM.png

Regards,

Josh

Like Sergey Karaev likes this

What exact type of field is "ParticipationTypeCF"? Is it just a normal Select List custom field?

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

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

Like Sergey Karaev likes this

Hi,

Thanks, the code worked. 

Neil

Glad to hear it worked, Neil.

Thx for using ScriptRunner!

Regards,

Josh

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

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.

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

 

HI

Can you please suggest how to set one value from various options in the screen selectbox using behaviour.

Regards
Shradha

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Apps & Integrations

Partner Webinar Opportunities: January 2022

Hi everyone 👋, I really like the format of the webinar opportunities summary that @Jimmy Seddon posts monthly on the Welcome Centre group. It's a great place to go to check that you didn...

133 views 3 11
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