Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

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

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 Sep 07, 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);

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 Sep 07, 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.

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

Got it working :)

 

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

 

Thank you

Blazej

Nir Haimov Community Leader Sep 11, 2018

@Blazej Borucki

You are welcome!

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

0 votes

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
TAGS

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