Setting Power Custom Field Pro value from groovy

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

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

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
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 Tuesday 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...

115 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