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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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.