Forums

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

Copy the value of two user-pickers custom field values into another custom field

Satyanarayana Singamsetti December 19, 2019

Hi ,

I need the code for Copy the value of two user-pickers custom field values into another custom field which is a multi user picker.

ex: CF1: user1, CF2: user2 and for CF3 the value should be as "user1,user2". CF3 is a User Picker (multiple users).

Note: CF3 will be empty during creation of issue. during the flow of issue once CF1 and CF2 gets values by the code CF3 should populate the merged value.

I tried with this below code but not worked :(

package UpdateIssue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.UpdateIssueRequest
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.project.Project
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.ModifiedValue

IssueManager issueManager = ComponentAccessor.getIssueManager();
MutableIssue issue = issueManager.getIssueObject("TKT-16")
if (issue)
{
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();

CustomField cstFld1 = customFieldManager.getCustomFieldObject("Customfield_1123")
CustomField cstFld2 = customFieldManager.getCustomFieldObject("Customfield_1123")
CustomField cstFld3 = customFieldManager.getCustomFieldObject("Customfield_1144")

ApplicationUser curUser = ComponentAccessor.getJiraAuthenticationContext().getUser();
UpdateIssueRequest updateIssueRequest = new UpdateIssueRequest(new UpdateIssueRequest.UpdateIssueRequestBuilder().eventDispatchOption(EventDispatchOption.ISSUE_UPDATED).sendMail(false))

// issue.setCustomFieldObject(cstFld1.getValue(issue).toString() + "," + cstFld2.getValue(issue).toString())
def CR = (cstFld1.getValue(issue).toString() + "," + cstFld2.getValue(issue).toString())
def changeHolder = new DefaultIssueChangeHolder()
cstFld3.updateValue(null, issue, new ModifiedValue(cstFld3,CR),changeHolder)
}

 

Getting this error

MUPERROR.png

I know why i get this error because

cstFld3 is Customfield with user picker and  CR is a string value, but don't know how to make string to custom field value(user picker).

Could some one help me on it.

Thanks in advance

 

1 answer

1 accepted

0 votes
Answer accepted
Satyanarayana Singamsetti December 24, 2019

Can some one help me on this ?

Suggest an answer

Log in or Sign up to answer