What is the empty value for a USER PICKER field - my script seems always returning "true"

Olivier Chen December 12, 2014

Hi,

I'm trying to add a "copy value from field to field" post function to my workflow - And I need it to be executed when condition is "true".

Please let me explain the scenario:
***************************************************************************
I need to get my issue assigned to the Component Lead automatically when it is being created (This is very easy to fulfill). But, I also have to assign to other people as needed (on the create-issue screen). That's not possible to put select user in "Assignee" system field (because it will still be assigned to the Component Lead). So, I added a new USER PICKER field, then add a post function to copy the value from the user picker field to the "Assignee" field.

I've tried with a few scripts, but was not successful.

Here are my 2 groovy scripts I put in [Conditional execution]:
***************************************************************************

// 1 //

if(!issue.get("customfield_11200")?.getName()){

 return true

} else {

 return false

}

 

//or *****************************

 

// 2 //

if(issue.get("customfield_11200").getName() != ""){

 return true

} else {

 return false

}

 

--------------------------------------------------------------------------
The issue is this script seems always return "true" value - means if I select a user then it works - if I keep it empty, then it throw errors - so the empty value here is not correct! I've tried "", null, empty - All are not accepted-.

Could you please advise what is the empty value for a user picker field??

OR, when I used the first script, it always return "true" - Assign to a user I put in the USER PICKER field or "Unassigned" when keep the filed empty.  How can I resolve this issue?

Thank you in advance!!

 

Thanks & Regards,
Olivier Chen

2 answers

1 accepted

0 votes
Answer accepted
JamieA
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.
December 12, 2014

As Nic said, you can just use a simplified version, but your code is wrong, there is no issue.get. Unless you're thinking of another plugin. The following will work :

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = customFieldManager.getCustomFieldObject("customfield_11200")
if (issue.getCustomFieldValue(customField)) {
    ...
}

But if this is in a condition block it's still simpler:

cfValues["Name of CF"]

That should be all you need to test if there is a value set.

 

Olivier Chen December 15, 2014

Thanks Nic and Jamie!

I tried the code and it works!

 

 

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.
December 12, 2014

When a custom field is empty, there's actually nothing in the database for it.  So all your "get" functions sort of fail.

But it does make your code more simple.  Try:

if (issue.get("customfield_11200")) { return true }

Which means "if there is a value, then do something"

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events