if_null
Returns one of two values depending on whether the test value is null. A value is considered null if it is None, an empty string, an empty list, or an empty dictionary.
Syntax
if_null(test_value, value_if_null, value_if_not_null)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| test_value | any | Yes | The value to test for nullness. |
| value_if_null | any | Yes | The value to return if the test value is null. |
| value_if_not_null | any | Yes | The value to return if the test value is not null. |
Returns
Type: any
Either value_if_null or value_if_not_null, depending on whether the test value is null.
Examples
Provide a fallback for missing descriptions:
if_null([description], "No description provided", [description])
If description is None or empty, returns "No description provided". Otherwise, returns the original description.
Map empty fields to a default identifier:
if_null([external_id], "UNKNOWN", concatenate("EXT-", [external_id]))
If external_id is null, returns "UNKNOWN". Otherwise, returns the ID prefixed with "EXT-".
Notes
- The null check covers
None, empty strings (""), empty lists ([]), and empty dictionaries ({}). - Numeric zero (
0) and booleanFalseare not considered null by this function. - For a simpler true/false conditional, use the
iffunction instead.
Comments
0 comments
Please sign in to leave a comment.