If condition: how to return nothing when the returned type is an entity?

Hi,

I am missing something? (I searched in this forum but found nothing)

The if function needs 3 arguments. So you cannot use: if(test, do this)
You must write: if(test, do this, do that)

If I want to do nothing, it’s easy when dealing with text: just return “” → `if(test, “test ok”, “”)´

But if the result of a test is an entity (say a Contact), what can I return? What is the equivalent of “” for an entity?
if(test, a_given_contact, ????)

Thanks

2 Likes

Do you mean in a formula field or within an automation/button?

In an automation rule.

In that case, you could use the filter().sort().first() functions in such a way as to return a null/empty result.
e.g. Contacts.filter(Name = "").sort().first() will give you zero contacts if all contacts have a name.

In fact, it might be possible in some cases that you could just use this formulation (with an appropriate filter condition) without needing the if condition.

1 Like

Thanks a lot Chris. It works. I understand we need a workaround here.
I will search for a more “frugal” workaround later.

I think the if condition should accept only 2 arguments or a NULL entity should exist.

Thanks again

1 Like