Is it possible to set null value to field of number type?

Hi there,

the default value of the number field is zero which results in confusion for the sales team … here is the scenario

I have a field called order_total of type number
and I have another called collected_amount of type number

now I wanna create a new field called remaining_amount of type number
the field will be calculated like this order_total - collected_amount
the thing is, when collected_amount is null I don’t wanna do the calculation and I wanna set the remaining_amount to be null too but it gets zero instead which is misleading

I’m using field expression … is there any way I can achieve that without using workflow? thanks

A bit of an unfortunate integration into the default value sanitation flow where the sanitiser defaults the invalid number into the zero-value. This does seem like a bug to me but I’ll check with the team on what exactly we want to do (we’ll probably mark it off as a bug).

Your current options:

Change that expression field into a Text input

Instead of having your expression return nil you’d return a ""; so something like this: !(aa ?? false) ? "" : "10" (expression written for my dummy module; adjust as needed).

Not sure what your use cases are, but this would probably do the trick. In this case, your queries would need to change into field = '' instead of field IS NULL.

Change the Number field into a multi-value field

This is a bit of a hack, but due to how Corteza handles multi-value fields, for most cases, this should behave exactly the same as the single-value counterpart.

The biggest change would be any workflows since you’d have to iterate the field (or use the record.values.field[0]) but querying should work out of the box.

The expression would look something like this: !(aa ?? false)? [] : [100] (again, adjust as needed).

1 Like

thanks @tjerman, I used the first option as workaround

please update the topic if you decided on a solution to the matter

Is there any development in this topic? I stumbled upon a similar issue where I need null and 0 to mean different things (price “not set” vs 0), but right now user can’t set null or empty numerical field - it defaults to 0. Even if I change it to null on database level, it’s treated as 0 in app.
Also, maybe because empty value gets converted to 0, isNil() function doesn’t work properly - it sees 0, so it always returns false.

This expression will reset it to undefined, it is a hack but it works.

image