Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

4 votes
Answer 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

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

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

The benefits of using Jira in different departments

Jira is a great tool to use across different departments. Forget that paperwork – switch to Jira and get that tasks done smoothly. Marketing Jira allows for a complete digital transformation of you...

97 views 0 5
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