Behaviour script for updating customfield not working

Archana Ganesan September 8, 2016

I'm trying to set a custom field list value based on another custom field's value.

In other words, if field1(label) has some labels added to it, set field2's(select list) value to "YES"

Here is my code that throws an exception:

def field1 = issueToUpdate?.getCustomFieldValue(customField1) // field1 is a list object

FieldConfig fieldConfig = customField2.getRelevantConfig(underlyingIssue)

def option = optionsManager.getOptions(fieldConfig).find {it.toString() == "YES"}

FormField field2 = getFieldByName("custom_Field_2")

if (  field1 != null ) {

   log.debug("field1 not empty, updating issue");

    field2?.setFormValue(option)

    log.debug("updated issue");

}

 

 

In the log:

/rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/runvalidator.json [c.a.p.r.c.error.jersey.ThrowableExceptionMapper] Uncaught exception thrown by REST service: null

java.lang.StackOverflowError

        at java.security.AccessController.doPrivileged(Native Method)

        at org.codehaus.groovy.reflection.CachedClass$3.initValue(CachedClass.java:89)

        at org.codehaus.groovy.reflection.CachedClass$3.initValue(CachedClass.java:87)

        ...

        at groovy.json.JsonOutput.getObjectProperties(JsonOutput.java:327)

        at groovy.json.JsonOutput.writeObject(JsonOutput.java:320)

        at groovy.json.JsonOutput.writeMap(JsonOutput.java:458)

        at groovy.json.JsonOutput.writeObject(JsonOutput.java:321)

        at groovy.json.JsonOutput.writeArray(JsonOutput.java:363)

        at groovy.json.JsonOutput.writeObject(JsonOutput.java:304)

 

 Please suggest other ways to set the custom field value

1 answer

1 accepted

1 vote
Answer accepted
JamieA
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.
September 12, 2016

The problem is you are setting the form value to an Option object, then getting a SO when we try to serialise that. (Which could probably be handled better on our side).

You need to set the form value to the option ID (I think, or the value - probably the ID):

field2?.setFormValue(option.optionId)
Archana Ganesan September 12, 2016

That worked, thanks Jamie.

Suggest an answer

Log in or Sign up to answer