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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

What is the null value for user pickers?

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 Community Leader Feb 05, 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')
}

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
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you