Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to resolve a ClassCastException error when copying a multiple User Picker?

Jeremy
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 10, 2024

We're in the process of a migration and I'm simply trying to use scriptrunner to copy data in a multiple user picker into another multiple user picker.  A snippet of the pertinent code is:

Issues.search("project = ABC and issuetype = story and 'Multiple Assignee' is not empty").each { issue ->
def mAssignee = issue.getCustomFieldValue('Multiple Assignee')
issue.update {
setCustomFieldValue('Collaborators', mAssignee)
}
}

Where both Collaborators and Multiple Assignee are multi user pickers.

I keep getting the error:

Something went wrong: ClassCastException

class java.util.ArrayList cannot be cast to class com.atlassian.jira.user.ApplicationUser (java.util.ArrayList is in module java.base of loader 'bootstrap'; com.atlassian.jira.user.ApplicationUser is in unnamed module of loader org.apache.catalina.loader.ParallelWebappClassLoader @5a12c728)

2 answers

1 accepted

1 vote
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
April 15, 2024

Hi @Jeremy

Your approach is currently not working because when you pass a value to a Custom Field using HAPI, you need to pass it as a String.

In your current approach, you are passing it as a List of Application Users, i.e. List<ApplicationUser> hence it fails to pass the value.

Please refer to this snippet for a working solution. 

Below is the sample working code from the snippet link above:-

import com.adaptavist.hapi.jira.issues.Issues
import com.atlassian.jira.user.ApplicationUser

Issues.search("""project = MOCK and "Multi User Picker" is not EMPTY""").each {
def issue = it
def users = issue.getCustomFieldValue('Multi User Picker') as List<ApplicationUser>

def selectedUsers = users.collect {
it.username
}.toString()

def updated = selectedUsers.replace('[','').replace(']','').trim()

issue.update {
setCustomFieldValue('Collaborators', updated)
}
}

Please note that the sample working code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

Below is a screenshot of the ScriptRunner Console configuration:-

console_config.png

 

Below are a couple of test screenshots for your reference:-

1. Before the code is executed in the ScriptRunner Console, if you notice, the issues below have options from the Multi User Picker field:-

test1.pngtest2.pngtest3.png

2. Once the code is executed in the ScriptRunner Console, the options from the Multi User Picker field are copied to the Collaborators field as shown in the screenshots below:-

test4.pngtest5.pngtest6.png

 

I hope this helps to solve your question. :-)

Thank you and Kind regards,

Ram

0 votes
Matt Parks
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.
April 10, 2024

It doesn't seem to think that both fields are lists of users.

In these instances, I'll put the code into Script Console and hard-code in a particular issue for the 'issue' variable. Then return the value from that custom field to see exactly what it's returning.

Matt Parks
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.
April 10, 2024

If you can put the return value here, that might help us troubleshoot.

Jeremy
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 10, 2024

It returns the users in a list Username(UserID):

[a617803(JIRAUSER34925), a61684(JIRAUSER35215)]

Matt Parks
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.
April 11, 2024

I could be mis-reading the error message, but it looks like either the Collaborators field is the single user field (which seems like it can't be right) or something odd is happening. One thing to try is to run the same code in the Script Console, but get the value of the Collaborators field from an issue with more than one user in it.

You might need to individually pull the users out of the Multiple Assignee field into a collection of users and then set that new collection as the value for the Collaborators field.

I'm assuming that the 'Multiple Assignee' and 'Collaborators' fields are defined variables from earlier in the script.



Collection<ApplicationUser> tempUserList
def mAssignee = issue.getCustomFieldValue('Multiple Assignee')

mAssignee.each
{
      tempUserList.add(it)
}

issue.setCustomFieldValue('Collaborators', tempUserList)


Even though this feels like you're doing the same thing, it wouldn't be the first time that I had to do some shenanigans to get objects to be the type that I expected them to be.

Suggest an answer

Log in or Sign up to answer