scriptrunner behavior to clear the value of a selection list field does not work in JSD portal

Tomas Arguinzones Yahoo September 23, 2020

Hi,

I have a simple behavior to clear the value of a selection field when the user selects No in another field, and the behavior does not work in the JSD portal. In the Jira UI works perfect (the selection list field value is cleared when the user selects No in another field), but in JSD portal just does not work. I have the proper mappings, so I have no clue why it does not work in JSD portal. Here is the server side script:

def SelectionListField = getFieldByName("List A")
def YesNoField = getFieldById(getFieldChanged())

def selectedOption = YesNoField.getValue() as String
def isYesSelected = selectedOption == "Yes"

SelectionListField.setHidden(! isYesSelected)
SelectionListField.setRequired(isYesSelected)

//clear SelectionListField value when YesNoField is No

if (!isYesSelected){

SelectionListField.setFormValue("")

}

 

I also tried this but it did not work:

SelectionListField.setFormValue(null)

 

And also tried this but it did not work either:

def optionsMap = ["-1": "None"]
SelectionListField.setFieldOptions(optionsMap)

 

As I said, in JIRA UI works fine but not in JSD portal.

 

Any ideas?

 

Thank you

4 answers

1 accepted

2 votes
Answer accepted
Marina Veselić July 21, 2021

Hi,

Try: getFieldByName("List A").setFormValue(-1)

Cheers,
Marina

0 votes
Jordan Hauser September 29, 2022

This may be an old issue but it pops up whenever I'm searching for the answer for this, so I'll record my findings here.

Bad Error - causes things to stay in GC

WARN jordan.hauser 853x3046576x1 1fxhefm 10.0.4.185,127.0.0.1 /browse/PR-5018 [c.atlassian.ozymandias.SafePluginPointAccess] Unable to run plugin code because of 'java.lang.NullPointerException - null'.


And in my experience from when I was first trying to figure it out, it leaves stuff in the garbage collector and WILL bring down your server even with ~150 people on it. On certain forms we have multiple tabs for individual line items, and needed some way to mass clear the line items.

Ok Error? - Doesn't appear to affect the GC

2022-09-29 14:13:51,555-0400 http-nio-8080-exec-14 url: /rest/scriptrunner/behaviours/latest/validatorsByPid.json; user: jordan.hauser WARN jordan.hauser 853x3046737x1 1fxhefm 10.0.4.185,127.0.0.1 /rest/scriptrunner/behaviours/latest/validatorsByPid.json [c.o.j.groovy.user.FormField] No option found for customfield_11682 with value -1


For text fields - setFormValue("") 
For number fields - setFormValue()
For select fields - setFormValue(-1), setFormValue("-1")

 

The syntax checker in any of the scriptrunner programming interfaces will yell at you for not including a value for that second one, but it does not produce the error and appears to run fine.

-Jordan

0 votes
Erwin Oliva July 14, 2022

We are on JIRA Server 8.20.2 and setFormValue(null) worked for us.

Erwin Oliva July 14, 2022

However, for our JIRA Server 8.4.1, setFormValue(-1) worked.

0 votes
Andreas Hibner
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 5, 2021

Hi Tomas,

tty this, it works fine:

myFormField.setFormValue(["-1", "None"])

Cheers,

Andi

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events