Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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

Neil Dixon November 7, 2018

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

Suggest an answer

Log in or Sign up to answer
5 votes
Answer accepted
Joshua Yamdogo @ Adaptavist
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.
November 8, 2018

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

Neil Dixon November 9, 2018

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

Joshua Yamdogo @ Adaptavist
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.
November 9, 2018

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
Joshua Yamdogo @ Adaptavist
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.
November 9, 2018

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

Neil Dixon November 9, 2018

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

Joshua Yamdogo @ Adaptavist
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.
November 9, 2018

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
Neil Dixon November 13, 2018

Hi,

Thanks, the code worked. 

Neil

Joshua Yamdogo @ Adaptavist
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.
November 13, 2018

Glad to hear it worked, Neil.

Thx for using ScriptRunner!

Regards,

Josh

SWAPNIL SRIVASTAV November 1, 2019

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

SWAPNIL SRIVASTAV November 3, 2019

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.

Neil Dixon November 4, 2019

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

Shradha Singh February 18, 2020

 

HI

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

Regards
Shradha

TAGS
AUG Leaders

Atlassian Community Events