Add users in multi users picker filed

Nadica Gaber September 15, 2017

I am using the following script to add values to users picker filed(multi user) and is added as a script post function:

 

import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.user.ApplicationUser

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueService = ComponentAccessor.getComponent(IssueService)
def approvers = customFieldManager.getCustomFieldObjectByName("Ticket Viewers")

def customFieldValue = issue.getCustomFieldValue(approvers);
//String selectedviewer = issue.getCustomFieldValue(approvers)
def issue = issue as Issue

def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser

def issueInputParameters = issueService.newIssueInputParameters()

// Adding the user names here
issueInputParameters.addCustomFieldValue(approvers.id, "username1", "username2")


def updateValidationResult = issueService.validateUpdate(user, issue.id, issueInputParameters)

if (updateValidationResult.isValid()) {
    issueService.update(user, updateValidationResult)
}

 

However, if there is already a value in the user picker field it gets deleted. Only username1 an username2 are left as values in the field.

Can somebody help me to just append two usernames to alreday populated filed?

1 answer

0 votes
Aleksandr Zuevich
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.
September 15, 2017

Suggest an answer

Log in or Sign up to answer