Post function to add users in a multi user picker field

Camille Lecerf July 31, 2018

Hi, 

When creating a sub-task I am trying to add users by their login id firstname_lastname to a Multi User Picker Customfield but it fails :

def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'My Multi User Picker Custom Field'}
issue.setCustomFieldValue(cf, 'firstname_lastname1, firstname_lastname2, firstname_lastname3,');

What is wrong please ?

Thanks & regards,

Camille

3 answers

0 votes
Camille Lecerf July 31, 2018

Hi Mark and Alexey,

Thank you for your help. Infortunately it did not work for me... I decided to use a workaround with an other plugin I have : Precondition: Value Field (JSU) + Update Any Issue Field (JSU)

0 votes
Mark Markov
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.
July 31, 2018

Hello @Camille Lecerf

Answer of @Alexey Matveev essentialy right. But UserUtil interface is deprecated and not recommended to use.

Use UserManager instead, here is script.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def userManager = ComponentAccessor.getUserManager()
def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'My Multi User Picker Custom Field'}
List<ApplicationUser> userList = new ArrayList<>()
userList.add(userManager.getUserByKey("user1"))
userList.add(userManager.getUserByKey("user2"))
userList.add(userManager.getUserByKey("user3"))
issue.setCustomFieldValue(cf, userList);
0 votes
Alexey Matveev
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.
July 31, 2018

Hello,

You need to pass an array of ApplicationUser.

It would be something like this:

def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'My Multi User Picker Custom Field'}
List<ApplicationUser> userList = new ArrayList<>()
userList.add(ComponentAccessor.getUserUtil().getUserByKey("user1"))
userList.add(ComponentAccessor.getUserUtil().getUserByKey("user2"))
userList.add(ComponentAccessor.getUserUtil().getUserByKey("user3"))
issue.setCustomFieldValue(cf, userList);

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events