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
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Got it working :)
((java.util.List)cfMultiSelectUserValue).add(currentUser).
Thank you
Blazej
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You are welcome!
Please mark my answer as the solution so this thread will be marked as closed.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Blazej,
I have the same issue. I request you to provide the code you used here. Thank You in advance
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.