Forums

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

Unable to set multi user picker value into another multi user picker

Swarna Radha
Contributor
August 27, 2018

Hi,

 

I want to copy the value of the multi user picker into another one.

I am able to retrieve the value but unable to set it.

Please see my code:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.user.util.UserManager

log.setLevel(org.apache.log4j.Level.DEBUG)

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
UserManager userManager = ComponentAccessor.getUserManager();

def approver = customFieldManager.getCustomFieldObjectByName("Approvers - IT Appli LM/TL")
CustomField multiUser = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Approved by IT- Appli Dev LM/TL")

String approver_value =issue.getCustomFieldValue(approver)

ApplicationUser Mgruser = userManager.getUserByName(approver_value)
log.debug("BRM: $Mgruser")

List<ApplicationUser> users;
if(users == null)
users = new ArrayList<>();

issue.setCustomFieldValue(multiUser, Mgruser);
IssueManager issueManager=ComponentAccessor.getIssueManager();
issueManager.updateIssue(user,issue,EventDispatchOption.ISSUE_UPDATED,true);

 

Thanks

Swarna

2 answers

1 accepted

1 vote
Answer accepted
Nir Haimov
Community Champion
August 27, 2018

Hi @Swarna Radha

Here is a working code

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager();
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def changeHolder = new DefaultIssueChangeHolder();

def cfMultiUser1 = customFieldManager.getCustomFieldObjectByName("from field")
def cfMultiUser2 = customFieldManager.getCustomFieldObjectByName("to field")

def cfMultiUser1Value = issue.getCustomFieldValue(cfMultiUser1)
def cfMultiUser2Value = issue.getCustomFieldValue(cfMultiUser2)

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

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

Just change the "from field" and the "to field" the the actual names of your fields

Swarna Radha
Contributor
August 27, 2018

Hi @Nir Haimov,

The code is working . Thanks  :)

Thanks

Swarna

0 votes
Danyal Iqbal
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.
August 27, 2018

issue.setCustomFieldValue(multiUser, Mgruser);

Mgruser is not a list<application..> type. replace Mgruser with users.

try users.add(mgruser)

and try the multiuser.updateValue(...) if the setcustomfieildvalue is giving you trouble.

Suggest an answer

Log in or Sign up to answer