Sometimes, when using a formula field that returns a single entity, the user might want to return an empty value (meaning no entity).
For example, if (X is true return entity Y, else return nothing)
There is a workaround for this, which is taking a collection of entities of the type returned and applying to it Collection.Filter(true = false).Sort(Some Field).First() which returns the first entity in an empty list (which is an empty value), but this is rather awkward.
Yes, it’s indeed unconventional that Fibery doesn’t allow a direct way to set a field to null in a formula.
In my case, I want to create a button with a formula that functions as a toggle to populate and clear a second Project relationship field (Active Project), which is also a to-one relation.
The suggested workaround does not work for to one relation fields.
I may not fully understand, but In my case I don’t have a collection field ‘Projects’. I have a Page entity with Project and Active Project fields which are both to-one relations.
So using ‘Projects’ results in ‘Reference to undefined variable Projects’
And using the filter on the Project field results in ‘Cant call ‘Filter’ method’.
If you are updating a field via an automation (button or rule) then all workspace dbs are accessible in formulas.
In my example above, Projects is the name of the database, not a relation field name.
Case:
That formula needs to result in the Project entity linked in the Active Project field, if the Active Project field is empty. If it is not empty, it should make the field empty.
What is the name of the database containing the Projects?
Note: if there is more than one db in the workspace with that name, you’ll need to qualify it with a space name.
Try typing the first few letters and let the auto complete make suggestions, and you should see what you need.
Yeah, it’s an ugly workaround, but you create a number field called “Blank” or something, hide it to keep it more out of the way and make sure you leave it empty, then you point to that field whenever you need a null value. It will break everything if someone updates it though, so keep it secret, keep it safe.
We must employ lots of work arounds to simply clear a value. The ability to set a value to equal null in order to clear the value would be fantastic. Thanks!
This would then work for all values, dates, text, select, etc. (except for required ones)
While I agree that there should be a way to set a value to NULL without having to resort to workarounds, what’s wrong with the “Clear Value” option that exists?
Ahh, didn’t know you were trying to use a formula.
What I do in those cases (again, not ideal, but it’s better than other methods in my opinion) is create a field in the database called “NULL DATE” (or NULL NUMBER or NULL USER, etc, etc) and then just use that field, that is always empty, as the value in your formula.
Like:
If(A + B = C, A + B, NULL NUMBER)
It’s especially helpful if you need to use null in several places in a single database.