Coalesce function in built-in functions
991
Views
7
Comments
On our RadarOn our Radar
Builtin & User functions

Variable ?? DefaultValue


if the variable is empty / null the DefaultValue is assigned

I'm not sure I understand. A variable, by default, has the default value. Which is the default value for the variable's type if no explicit default is specified.

A default value would be assigned once when the variable is created.  It can still be set to null later on.  The coalesce function would at run-time instant decide whether to use a default value or not.

I still don't understand: when the variable is "created", i.e. when it is defined, it already gets the default value.

Kilian, I think what Bruno is trying to say is this:

Variable ?? AlternativeValue

If the variable is null, use the alternative value instead, i.e. Employee.FirstName ?? "N/A"

The thing is though, there are no NULL values in the Platform. So there's no way we can test for a NULL value, since they don't exist!

Here is my answer, my equivalent, using existing functions (an If statement).  Used for a dropdown that produced completely blank values if the titles were not set (Id = 0).  Resulting in: "Name - QA Inspector" or "Name - (Unknown Title)" depending on if a title was associated with the Name.

SyntaxEditor Code Snippet

ApproversList.Label + " - " + If(ApproversTitles.Label<>"",ApproversTitles.Label,"(Unknown Title)")

+1 

For the number of times I've added these functions to my own modules, just to override the platform-default values when business required non-zero or non-empty default values.


CoalesceText(Var, Default) = If(Var <> "", Var, Default)
CoalesceInteger(Var, Default) = If(Var <> 0, Var, Default)
CoalesceLongInteger(Var, Default) = ...