I have a contacts table. It contains
NamePreferred fields. The
NameFirst field always has content. The
NamePreferred field sometimes has content.
I want to display the full name using the
NamePreferred if it has content else using the
NameFirst if the
NamePreferred field is empty.
How would I achieve such a thing?
August 15, 2022, 4:27pm
In a text display object, you could use a formula like
?(NamePreferred = "", NameFirst + " " + NameLast, NamePreferred)
The ?( function first evaluates the first parameter to see if it is true or false. If it’s true it returns the value of the second parameter, and if it’s false, it returns the value of the third parameter.
Thank you! That solved my problem!
August 15, 2022, 7:55pm
The ?( function mentioned by Dave is a great all-purpose function for this kind of problem. I use it all the time.
In this situation, there is also another function that could be used, the defaulttext( function.
There’s nothing wrong with using ?( for this formula, I just wanted to mention this alternative since it’s a bit simpler for this particular application.
Sorry, I actually edited the
?( so that I would always have the full name, either preferred name + last name or first name + last name.
My full expression was:
?(NamePreferred = "", NameFirst + " " + NameLast, NamePreferred + " " + NameLast)
Replacing it with:
defaulttext(NameFirst + " " + NameLast, NamePreferred + " " + NameLast)
Does not work. It only gave me last names where the
NamePreferred was empty.
August 17, 2022, 3:14pm
It does not work, because the second argument is not empty this way.
Use this instead:
defaulttext(NameFirst, NamePreferred) + " " + NameLast
I see the light! Thank you!