How to copy value of MultiUser picker field to Assignee field

SWAPNIL SRIVASTAV February 8, 2021

Hello Everyone,

I want to set the first selected user in the list of Multi-User picker as the value of Assignee field. I used in built post function of JSU (JIRA Suite Utilites plugin) and the below code in custom script post function:

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

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def uatTesters = customFieldManager.getCustomFieldObjectsByName("UAT Testers").first()
if(issue.getCustomFieldValue(uatTesters)) {
List<ApplicationUser> uatTestersVal = (List<ApplicationUser>) issue.getCustomFieldValue(uatTesters)
issue.setAssignee(uatTestersVal[0]) }

 

Both methods result in populating Assignee field with the user whose Full Name has alphabetical precedence. How can I set the assignee field with the first selected user in list.

Any help would be appreciated. Thanks in advance.

1 answer

0 votes
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 8, 2021

Hi

There is no inherent sequence to the list of users associated with a Multi-User Picker.

In fact, it is my observation that the list is always sorted alphabetically with every save operation. 

At the database level, there would be an incrementing unique id for each value instance. But with each save/update, the whole list is removed/replaced with the new list of users and the user list is always alphabetical.

So if the first user has a different significance compared to the other users, you must separate that user into a separate field: like "primary" and "others". Then you can change the assignee to the primary user field.

SWAPNIL SRIVASTAV February 9, 2021

Hello @Peter-Dave Sheehan ,

Thank you for the reply.

When you say- "you must separate that user into a separate field: like 'primary' and 'others'", what exactly do you mean?

Could you please elaborate on this.

Thanks and Regards

Swapnil Srivastav

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 9, 2021

I don't really have details about your scenario.

But conceptually, you appear to have 2 different business uses for users that are currently stored in the multi-user picker field. 

So I am suggesting you separate that first user into its own field. 

If, for example, your user picker field is used to designate a team. And the "first user" is meant to be the team captain. Then you should have 2 custom fields:

  1. team captain - single user picker
  2. rest of the team - multi-user picker

This way, in your script, you can be certain that you can always select the team captain by looking at the correct field.

SWAPNIL SRIVASTAV February 9, 2021

Hello @Peter-Dave Sheehan ,

That is a very creative workaround. But at the moment, we have to work with multi-user picker only.

Thank you for the reply

Regards

Swapnil Srivastav

Suggest an answer

Log in or Sign up to answer