Calculated Field - null

Hello Tabidoo,

I have a calculated field that concatenates values from several other fields. If one of the source fields is empty, the calculated field shows null in the output.

Is it possible to set the calculation so that when a source field is empty, it returns an empty string (“”) instead of null - so nothing is displayed in that place?

Example:

First name: Tomáš
Last name: Fuk
Title: (empty)
Calculated field: Title + First name + Last name
Desired result: Tomáš Fuk (not null Tomáš Fuk)

Thank you.

Yes — it’s possible. In your calculated field, you can replace null/empty inputs with an empty string and then join only the non-empty parts.

(() => {
  const parts = [
    doo.model["Title"]?.value,
    doo.model["First name"]?.value,
    doo.model["Last name"]?.value
  ]
    .map(v => (v == null ? "" : String(v).trim()))
    .filter(v => v !== "");

  return parts.join(" ");
})()
1 Like

Great! It works.
Thanks

Hi Filip,

I’ve encountered an issue where the code initially works correctly, but after one or two edits of the table, the value disappears and Tabidoo shows no result in the calculated field.

I’ve noticed that this seems to be related to a change Tabidoo makes to the code after the table edit window is saved.
In the first screenshot, you can see the original code, which works correctly. The second screenshot shows how the code looks when I open the edit window again; after saving it in this state, the calculation stops working.

Thank you for taking a look at this.

Clipboard01
Clipboard02

Hi,

try this.

(
  ( doo.model["ulice"]?.value ?? "").toString().trim() +
  " " +
  ( doo.model["psc"]?.value ?? "").toString().trim()
).trim()

image

1 Like

Thank you! It works and helped me find an alternative solution that appears to work correctly and behaves better, as it does not add a comma when a field contains no data:

[Ulice, PSC, Mesto, Zeme]
.map(v => (v ?? “”).toString().trim())
.filter(v => v.length > 0)
.join(", ")

1 Like