Trying to copy value from single user picker to multi user picker

Blazej Borucki September 7, 2018

Hello,

Not very familiar with groovy, but managed to get some things wroking. Unformtunately I have an issue with copying single user picker value to multi user picker value. Trying to do that for some time, but with no success so at the moment as workaround I'm just copying single to single.

 Here is the current code for single to single copying, as a workarounf

...some code...

def  cfMultiUser1 = customFieldManager.getCustomFieldObjectByName(field);
log.info("username2 ${field}") 
log.info("username3 ${cfMultiUser1.toString()}") 
     def cfMultiUser1Value = issue.getCustomFieldValue(cfMultiUser1)
     log.info("nazwa1 ${cfMultiUser1Value.toString()}")


def cfMultiUser2Value = issue.getCustomFieldValue(cfMultiUser2)

cfMultiUser2.updateValue(null, issue, new ModifiedValue(cfMultiUser2Value, cfMultiUser1Value),changeHolder);

issueManager.updateIssue(user,issue,EventDispatchOption.ISSUE_UPDATED,true);

 it is working, but when trying to use multi user picker as the destination field always get some issues, or the value is just empty.  

I was trying to put the user from first filed into list but it doesn't work. I tried different solutions but all are invalid. One of them is:

 

List<ApplicationUser> users
 users = new ArrayList<>();
users.add(ComponentAccessor.getUserManager().getUserByName(cfMultiUser1Value.toString()))
cfMultiUser2.updateValue(null, issue, new ModifiedValue(cfMultiUser2Value, users),changeHolder);



 I'm running jira v. 7.10.2

I will appreciate any suggestions.

 

Thank you

Blazej 

2 answers

1 accepted

1 vote
Answer accepted
Nir Haimov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 7, 2018

Hi,

So you said you want to add value from single user picket to multi user picker.

Here is a working code, in this example i took the current logged in user and added it to a multi select user picker field, but instead you can take any customfield with a single user picker value, it's the same.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def changeHolder = new DefaultIssueChangeHolder()
def cfMultiSelectUser = customFieldManager.getCustomFieldObjectByName("Testers List")
def cfMultiSelectUserValue = issue.getCustomFieldValue(cfMultiSelectUser)

cfMultiSelectUserValue.push(currentUser)
cfMultiSelectUser.updateValue(null, issue, new ModifiedValue(cfMultiSelectUserValue, cfMultiSelectUserValue),changeHolder);
Blazej Borucki September 7, 2018

Thank you Nir.

Unfortunately I'm getting error (cannot find matching object for the push) in you code, same if I use it with user taken from user picker. 

Which version of jira are you running? 

Nir Haimov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 7, 2018

Hi,

Jira 7.3.7 it should be the same.

the "push" is for the multi user picker field value, which is an ArrayList.

It doesn't matter what is the Jira version, it's coding, ArrayList have push.

If you are getting an error on the "push" than you did not use my code right.

Check again my code and your changes in it.

Basically, all you need to change in my code is the "Testers List", change it with your multi select user picker field name.

Blazej Borucki September 10, 2018

Hello,

 

unfortunately I'm getting the same issue with your code copied 1-1 with the field name change only. cannot find matching method java.lang.object#push (com.atlassian.user.ApplicationUser).

 

Blazej

Blazej Borucki September 10, 2018

Got it working :)

 

((java.util.List)cfMultiSelectUserValue).add(currentUser).

 

Thank you

Blazej

Nir Haimov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 11, 2018

@Blazej Borucki

You are welcome!

Please mark my answer as the solution so this thread will be marked as closed.

0 votes
Kumar Kumar
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!
December 8, 2020

Hi Blazej,

 

I have the same issue. I request you to provide the code you used here. Thank You in advance

Suggest an answer

Log in or Sign up to answer