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)
The answer is:
if (userPickerFieldValue)
You are probably missing something before. Here is a code snippet that can be executed in the script console:
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 {
......
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.