Script Runner build-in script Copy custom field values - error for copy from User Picker to multi user picker

Alexandru Baltes July 6, 2015

Hello,


I have to "convert" a custom field from User Picker(single) to Multi User Picker.


For this purpose I created a new custom field of type multi user picker and used the Script Runner plugin, build-in scripts, copy custom field values script (prebuilt).
The preview works fine, as can be seen in screenshot "preview", but when executed it fails with the error (from jira log):
2015-06-25 09:30:25,231 http-apr-8080-exec-25 ERROR qxb8016 570x26508x1 1trv3og 172.17.2.134 /rest/scriptrunner/latest/canned/com.onresolve.scriptrunner.canned.jira.admin.CopyCustomField [common.error.jersey.ThrowableExceptionMapper] Uncaught exception thrown by REST service: com.atlassian.jira.user.DelegatingApplicationUser cannot be cast to java.util.Collection
java.lang.ClassCastException: com.atlassian.jira.user.DelegatingApplicationUser cannot be cast to java.util.Collection
at com.atlassian.jira.issue.customfields.impl.AbstractMultiCFType.createValue(AbstractMultiCFType.java:39)
at com.atlassian.jira.issue.fields.CustomFieldImpl.createValue(CustomFieldImpl.java:831)
at com.atlassian.jira.issue.fields.CustomFieldImpl.updateValue(CustomFieldImpl.java:505)
at com.atlassian.jira.issue.fields.CustomFieldImpl.updateValue(CustomFieldImpl.java:487)
Please find also the attached screenshot of the error from Jira GUI.
java.lang.ClassCastException: com.atlassian.jira.user.DelegatingApplicationUser cannot be cast to java.util.Collection
at com.atlassian.jira.issue.customfields.impl.AbstractMultiCFType.createValue(AbstractMultiCFType.java:39)
at com.atlassian.jira.issue.fields.CustomFieldImpl.createValue(CustomFieldImpl.java:831)
at com.atlassian.jira.issue.fields.CustomFieldImpl.updateValue(CustomFieldImpl.java:505)
at com.atlassian.jira.issue.fields.CustomFieldImpl.updateValue(CustomFieldImpl.java:487)
at com.atlassian.jira.issue.fields.OrderableField$updateValue.call(Unknown Source)
at com.onresolve.scriptrunner.canned.jira.admin.CopyCustomField.doScript(CopyCustomField.groovy:202)

Builtin_Scripts.jpg

preview.jpg

error.jpg

 

 

2 answers

1 accepted

0 votes
Answer accepted
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 6, 2015

The built-in script can only copy between fields that hold data in the same structure.

A user picker field holds a user object as data, whereas a multi-user picker holds an array of user objects.

You're going to need to write something yourself.  Although it would be virtually identical to the existing copy, it just needs to stuff the existing user object from the source field into the first line of a new array for the target.

Alexandru Baltes July 6, 2015

Hi Nic, thank you for the fast reply. Ok, I see. In your opinion, would this be the most suitable option (create a one-time script)? It will affect aprox. 17000 issues. Or do you see fit another way? Thank you! Best regards, Alex

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 7, 2015

I'd never recommend direct access to the database. That said, in this case, it's close to being the best option and you've done exactly the right thing. With two caveats: 1. You might want to update the searcher as well. But do it in the UI 2. Once you've checked that is ok, I would recommend a full re-index as soon as you can afford the downtime (not the background one, a full one)

Alexandru Baltes July 7, 2015

Regarding the searcher, I am on the safe side. All the multi-user custom fields, as well as the "old" single-user custom field have the "com.atlassian.jira.plugin.system.customfieldtypes:userpickergroupsearcher" searcher, so no change would be required. I will also perform a full reindex. Thank you for your help!

Verhás István
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.
December 2, 2015

Nic hi, Actually the documentation of the script runner states the following: "Copy Custom Field Values For each issue returned by a query, this will copy values from one custom field to another. This is useful if you want to convert the type of a custom field. If the two custom fields have different types, you may not be able to use this. The following conversions are handled: Single to multi, eg single select to multi select, single user picker to multi user picker. ....... " I have investigated the exception as I got the same and found the only problem is that the list of the multi type CFs does not contain the MultiUserCFType. I have successfully used it after the following modification Original List MULTI_TYPE_LIST = [MultiSelectCFType.class] Fixed List MULTI_TYPE_LIST = [MultiSelectCFType.class,MultiUserCFType.class] I propose to fix it in the official package as well. If you provide the git url to clone and push i would do it.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 2, 2015

So it's exactly what I said - incompatible types. I'm not sure if Jamie and his team are interested in covering every single edge-case in that much detail - the point of the script runner is to let you do what you need, not to match every single possibility. But you can always raise it as an improvement request over at https://productsupport.adaptavist.com/servicedesk/customer/portal/2/user/login?destination=portal%2F2

0 votes
Alexandru Baltes July 7, 2015

I have discovered one other way: 1. I have stopped the Jira instance. 2. I have updated, directly in the database, the Custom Field type: UPDATE customfield SET CUSTOMFIELDTYPEKEY='com.atlassian.jira.plugin.system.customfieldtypes:multiuserpicker' where id = <cf_id> 3. Start the Jira instance I have tested this on the non-productive environment and the test went well, now the old custom field (single user picker) is a multi-user picker. As mentioned, this operation is a one time only procedure. Would this be not recommended? Thank you! Best regards, Alex

Suggest an answer

Log in or Sign up to answer