It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Setting Power Custom Field Pro value from groovy

Tyler Miller Aug 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 Aug 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 Sep 05, 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
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Marketplace Apps & Integrations

Join our webinar: “Asset Management: The Role of Context in ITSM” with Atlassian & Riada

  Hi Atlassian Community! This is Teresa from the Jira Service Desk team. On June 19th, I’ll be hosting a webinar “Asset Management: The Role of Context in ITSM” with Atlassian Partne...

149 views 2 3
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you