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:
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)
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:-
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:-
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:-
I hope this helps to solve your question. :-)
Thank you and Kind regards,
Ram
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you can put the return value here, that might help us troubleshoot.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It returns the users in a list Username(UserID):
[a617803(JIRAUSER34925), a61684(JIRAUSER35215)]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.