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

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 vote

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.

 

Thanks Nic and Jamie!

I tried the code and it works!

 

 

0 vote

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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published May 30, 2018 in Marketplace Apps

Three tips for boosting your board's efficiency with Story Maps

Trello is one of the most effective tools for driving your sprints. It's customizable for every Agile team and product owners and Scrum masters (SM) love it. However, Agile teams often struggle with:...

855 views 2 9
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you