What is the null value for user pickers?

Christoph Schmitz February 5, 2020

Hello,

I react on a user picker in my behaviour plugin (Initializer) and need to check wether it is a user selected -> hide another customfield123 or no user selected (initially) -> hide customfield123:

if (userpicker == null)

   set CustomField123 hidden (true)

else

   set CustomField123 hidden (false)

Seems like (userpicker == null) doesn't work or still returns some value, because my customfield is always shown altough there is no user select. If if I use (!userpicker) it still has no effect.

Also following has no effect:

if (userpicker)

   set customfield123 hidden (false)

else

   set customfield123 hidden (true)

 

1 answer

1 accepted

0 votes
Answer accepted
Leonard Chew
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.
February 5, 2020

The answer is:

if (userPickerFieldValue) 

You are probably missing something before. Here is a code snippet that can be executed in the script console:

  • Replace issueKey "ENT-191" with a valid issue of yours
  • Replace "MyUserPickerField" with the fieldname of your user picker field

 

import org.apache.log4j.Level
log.setLevel(Level.DEBUG)

import com.atlassian.jira.component.ComponentAccessor

def issueKey = "ENT-191"
def issueManager = ComponentAccessor.getIssueManager()
def issue = issueManager.getIssueObject(issueKey)

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def userPickerField = customFieldManager.getCustomFieldObjectsByName("MyUserPickerField")[0]
def userPickerFieldValue = issue.getCustomFieldValue(userPickerField)
if (userPickerFieldValue) {
log.debug('Users in Field: ' + userPickerFieldValue)
} else {
log.debug('No users in Userpicker Field')
}
Christoph Schmitz February 7, 2020

Thanks, I already found the mistake but it was as u said, i forgot the ".getValue()" at the end.

Following works now:

String userpicker = getFieldByName("userpicker").getValue();

if ( userpicker == null || userpicker.isEmpty() ) {

......

} else {

......

}

Suggest an answer

Log in or Sign up to answer