Invalid value while set field options dinamically in behaviour validation script

Good day,

I have a question about adding field options to SELECT control by using validation script in behaviour plugin.

On create issue screen I have SELECT that I filled by using result of filter query (script below).

But then I try to press "Create" to finish adding new issue, validation message is appearing:  

Invalid value 'xxx' passed for customfield 'selectfield'. Allowed values are: key1[1],key2[2], -1

Allowed values - values, that we set in custom field settings, but not values that we added dinamically.

 

imports ...
 
// find fields
FormField formComponent = getFieldById(fieldChanged)    	// field
FormField formSelect = getFieldById("customfield_11703")   	// select
 
// find issue list by filter result
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def ctx = new JiraServiceContextImpl(user)
def searchRequestService = ComponentManager.getInstance().getSearchRequestService()
def searchProvider = ComponentManager.getInstance().getSearchProvider()
def sr = searchRequestService.getFilter(ctx, 12800)
def searchResult = searchProvider.search(sr?.getQuery(), user, PagerFilter.getUnlimitedFilter())
def issueManager = ComponentManager.getInstance().getIssueManager()
def issues = searchResult.getIssues().collect {issueManager.getIssueObject(it.id)}

// add issue list to form select (to make dinamic result)
Map fieldOptions = [:] 
def index = issues.size() - 1;
for ( issue1 in issues ){
    def name = issue1.getKey()
    fieldOptions.put(index as String,name)
    index--;
}
formSelect.setFieldOptions (fieldOptions)

How to avoid/change validation to avoid this?

Or how to set new fiels options to select custom field to avoid this error?

2 answers

1 accepted

0 vote

You can only restrict the list of options with a select or multiselect. The map you provide should have keys which equal the IDs of the Option objects. The values can be any string though.

It will be possible to do this in the next (or next + 1) version. Right now though for whatever option ID you set, that needs to be a valid option for the field.

Thank Jamie for your involvement! May be have any ideas how can we put a single select field of issue list returned by filter on a creation issue screen?

Hi Jamie,

I have the same issue, can u please explain me how to map the keys with the IDs of option objects.

 

Thanks in advance.

Hi Oleg,

I am not able to configure the custom fields in the Query issues custom fields plugin.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

163 views 0 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you