Setting Power Custom Field Pro value from groovy

Tyler Miller August 30, 2017

I have an existing groovy script that creates issues, however I cannot seem to figure out how to set a value of a KCF pro field. It seems to require the value to be in com.keplerrominfo.jira.plugins.keplercf.pro.optionscf.customfield.SocOptionImpl, however that class is not being exported. Is there a trick to be able to get and set the value from these fields?

I have a hack in place right now, where I create the issue with groovy, then have a SIL listener on the create event that copies the value from another field.

I tried porting over my groovy script to SIL a while back, however there were a few functions missing in SIL that prevented me from doing so. So for now I am stuck with groovy.

1 answer

1 vote
Alexandra Topoloaga
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.
August 31, 2017

Hi,

 

The values of KCF Pro fields are structures of KPOption type, which means they come in (label, value) pairs.

So, in order to set the value you must provide a label and a value. 

It should be similar to how we set the default values for the fields, an example is here

 

Hope this helps,

Alexandra

Tyler Miller September 5, 2017

That was actually the first thing I tried. But when passing the value as string.
'{"label":"","value":"10000"}' I get an error:

java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Collection
at com.keplerrominfo.jira.plugins.keplercf.pro.optionscf.customfield.SILOptionsCFtype.valuesEqual(SILOptionsCFtype.java:60)
at com.atlassian.jira.issue.fields.CustomFieldImpl.valuesEqual(CustomFieldImpl.java:1601)
at com.atlassian.jira.issue.fields.CustomFieldImpl.updateValue(CustomFieldImpl.java:462)
at com.atlassian.jira.issue.fields.CustomFieldImpl.updateValue(CustomFieldImpl.java:434)
at com.atlassian.jira.issue.managers.DefaultIssueManager.updateFieldValues(DefaultIssueManager.java:704)
at com.atlassian.jira.issue.managers.DefaultIssueManager.updateIssue(DefaultIssueManager.java:669)
at com.atlassian.jira.issue.managers.DefaultIssueManager.updateIssue(DefaultIssueManager.java:655)
at com.atlassian.jira.issue.IssueManager$updateIssue$0.call(Unknown Source)
at Script221.run(Script221.groovy:39)

When I pass it [label:"",value:"10000"] I get:

java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to java.util.Collection
at com.keplerrominfo.jira.plugins.keplercf.pro.optionscf.customfield.SILOptionsCFtype.valuesEqual(SILOptionsCFtype.java:60)
at com.atlassian.jira.issue.fields.CustomFieldImpl.valuesEqual(CustomFieldImpl.java:1601)

and when I pass it [[label:"",value:"10000"]] i get:

java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to com.keplerrominfo.jira.plugins.keplercf.pro.optionscf.customfield.SocOption
at com.keplerrominfo.jira.plugins.keplercf.pro.optionscf.customfield.SILOptionsCFtype.convertTypeToDbValue(SILOptionsCFtype.java:60)
at com.atlassian.jira.issue.customfields.impl.AbstractMultiCFType.convertTypesToDbObjects(AbstractMultiCFType.java:190)
at com.atlassian.jira.issue.customfields.impl.AbstractMultiCFType.updateValue(AbstractMultiCFType.java:142)
at com.keplerrominfo.jira.plugins.keplercf.pro.optionscf.customfield.SILOptionsCFtype.updateValue(SILOptionsCFtype.java:304)
at com.keplerrominfo.jira.plugins.keplercf.pro.optionscf.customfield.SILOptionsCFtype.updateValue(SILOptionsCFtype.java:60)
at com.atlassian.jira.issue.fields.CustomFieldImpl.updateValue(CustomFieldImpl.java:464)

the ouput of a getCustomFieldValue where it's already set gives me:

[SocOptionImpl{label='', value='25002'}]

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events