How can I set a Scriptrunner condition on any of multiple user picker fields being empty?

Rob Horan
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 3, 2020

I need to send an email to a group (I believe a Jira group) if one of 4 user picker fields is empty.

The only plugin I seem to have available at my disposal to do this is ScriptRunner, and it requires syntax which I am woefully unfamiliar with. 

Before sending me hatemail about an answer being out there, please know that I tried looking and I saw various examples showing various ways of dealing with a single user picker field, but not how to create a condition in which any of multiple fields is empty.  (null)

1 answer

1 accepted

2 votes
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 3, 2020

This should return true is any of the fields is null. Just adjust the fieldNames

import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.customFieldManager

def fieldNames = ['multiUserFiel1','multiUserField2']
fieldNames.any{fieldName->
def customField = customFieldManager.getCustomFieldObjects(issue).find{fieldName}
customfield && issue.getCustomFieldValue(customField) == null
}
Rob Horan
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 3, 2020

Thanks!  I am assuming this will work with any field, single or multi user picker, or any other field.  Is that right?

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 3, 2020

Presumably yes.

I'm not sure if there are any types of field that would ever have a non-null representation of an empty value.

It's possible that a free text field that was populated in the past, when cleared would return an emtpy string rather than a null.

So we can instead use the following (also corrected an error I made in the first instance):

import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.customFieldManager

def fieldNames = ['multiUserFiel1','multiUserField2']
fieldNames.any{fieldName->
def customField = customFieldManager.getCustomFieldObjects(issue).find{it.name == fieldName}
fieldName && !issue.getCustomFieldValue(customField)
}
Like Rob Horan likes this

Suggest an answer

Log in or Sign up to answer