Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Get custom field size for a multi select User

Swarna Radha July 7, 2020

Hi,

 

I am doing a validation to check that only 2 users can be added in the multi users pickers.

Iam getting error on the last line. Please advice.

import com.atlassian.jira.component.ComponentAccessor
//ComponentAccessor.attachmentManager.getAttachments(issue).size() >= 1

ComponentAccessor.customFieldManager.getCustomFieldObjects(issue)?.findByName("Multi user picker").size() >= 1

 

Thanks,

Swarna

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
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.
July 8, 2020

Your code is getting a list of custom fields with the name "multi user picker" and looking at the size of that list.

What you really want to do is get the current value of the field for the current issue try something like

final String customFieldName = "My Custom Field"

def customFieldManager = ComponentAccessor.customFieldManager
def customField = customFieldManager.getCustomFieldObjects(issue).findByName(customFieldName)
assert customField : "Could not find custom field with name $customFieldName"

def customFieldVal = issue.getCustomFieldValue(customField)

def numberOfOptions = customFieldVal.size()

TAGS
AUG Leaders

Atlassian Community Events