how to use the Add or remove options to single or multi-select fields Based on

hi

I try the use  "Add or remove options to single or multi-select fields" Exmpel

I copy the Exmple form  the page, in tow the Script line and I changed the

from  FormField formSubcomponent = getFieldByName ("Subcomponent") to ormField formSubcomponent = getFieldByName ("system")

form   fieldOptions.put ("-1", "None") to    fieldOptions.put ("15804", "system")

and I get the Error

" Compilation failure: startup failed: Script1.groovy: 59: unable to resolve class GenericValue @ line 59, column 22. GenericValue component = componentManager.getProjectManager().getComponent(Long.parseLong(componentId)) ^ 1 error"

 I use JIRA  6.3 server 

 

tank u 

 

 

 

 

 

 

the script

public void setSubComponentOptions () {

    FormField formComponent = getFieldById(fieldChanged)

    FormField formSubcomponent = getFieldByName ("system")

 

    Object componentFormValue = formComponent.getFormValue()

    List componentIds = []

 

    if (componentFormValue instanceof List) {

        componentIds.addAll(componentFormValue as List)

    }

    else {

        // could be an empty string if all components are deselected

        if (componentFormValue) {

            componentIds.add(componentFormValue)

        }

    }

 

    Map fieldOptions = [:]

    fieldOptions.put ("15804", "system")

 

    for (Long componentId : componentIds) {

        try {

            Long.parseLong(componentId)

        } catch (NumberFormatException e) {

            log.error ("Could not get component Id as Long")

            return

        }

 

        GenericValue component = componentManager.getProjectManager().getComponent(Long.parseLong(componentId))

 

        switch (component?.get("name")) {

            case "Component 1" :

                fieldOptions.putAll (["Lemons":"Lemons", "Oranges":"Oranges"])

                break

 

            case "Component 2" :

                fieldOptions.putAll (["Spinach":"Spinach", "Celery":"Celery"])

                break

 

        }

    }

    formSubcomponent.setFieldOptions (fieldOptions)

}

 

                

1 answer

0 vote

Unfortunately that code is quite out of date now. The difference is that the map that contains the field options needs to be in the format:

[ optionId : optionValue ]

for example:

["10000":"Spinach", "10001":"Celery"]

I answered a question on this topic very recently, but the search is bad and I can't find it. The code for the answer is here: https://gist.github.com/jechlin/d9b8e778041c02e04270


Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

345 views 0 6
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