Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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

Suggest an answer

Log in or Sign up to answer
4 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.
Nov 08, 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

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.
Nov 09, 2018 • edited

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.
Nov 09, 2018

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

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.
Nov 09, 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

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.
Nov 13, 2018

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

TAGS
AUG Leaders

Atlassian Community Events