how to get the first value of multi user picker by script runner?

Ji Li March 30, 2021

I have a multi-user picker field, and would you let me know how I can get the first user in this multi-user picker field by script runner? Then, I would set the value to assignee field automatically. Thanks!

2 answers

1 accepted

0 votes
Answer accepted
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 31, 2021

A simple "get data from custom field" call will get a collection of users from a multi-user field, which you can then iterate over to get individual entries.

However, that collection is not sorted, so there's not going to be a clear definition of "first".  What is your definition of "first" here?

Ji Li April 2, 2021

Hi Nic, thanks for your replying. Suppose the collection of users is a list, say listA, so "first" means the first user which is input into this field, such as listA[0]. And would you show the code how to get the value of the multi-user field, and how to get the first item of the collection? Thanks for your help. I'm new to ScriptRunner. 

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 2, 2021

Jira doesn't record that, it can't because of the nature of the field.

Imagine this sequence:

  • Fire up a browser and go create an issue with a multi-user picker.  
  • Put in Charlie 
  • Put in Bob
  • Put in Alice 
  • Remove Charlie from the list
  • Click create

The important thing here is that the browser is not sending any data about the field to Jira until the create button is hit.  At that point, the field contains "Alice and Bob", there's no data about the order they were chosen.

So, as the field has no data about the order people were added to it, you can't extract the"first" user by your definition.

You'll need to think of a different rule for who is "first"

Ji Li April 5, 2021

Got it. Thanks, Nic.

0 votes
Ji Li April 2, 2021

wrong item

Suggest an answer

Log in or Sign up to answer