Null Values of Input fields not getting populated

Null Values of Input fields not getting populated

  

Hi,

I have a form which is mapped to a record in the database table. I get the record in preparation based on some filters. But if there is no record the form gets populated with "0" as its values and not the null value. Why is it so?


Thanks,

Neha

Hi Neha,

There's always a record, even if its values are empty. In Outsystems, variables, parameters and attributes can't have a null value. Instead, simple types (like Integer, Text etc.) have a default value. Integers, Long Integers and Decimals default to 0, Text defaults to the empty string "", Booleans are False. You can also manually change the default value of Attribute, if you don't they get the "default default" value I described above.

Then there's the Null Value property of Input Widgets. If the Variable (or, as is the case with a Form, the Attribute of the Record Variable) had the same value as specified for the Null Value, the Input will be empty (and the Prompt shown). So if the Variable/Attribute is "0" and the Null Value is also "0", you shouldn't see the "0" in the Input.

HI Neha,

I guess this is happening with integer fields only , you can set the Null Value property of your input to NullIdentifier() to avoid initial 0 in the input box.

Please see below.



Regards

-PJ-

Kilian Hekhuis wrote:

Hi Neha,

There's always a record, even if its values are empty. In Outsystems, variables, parameters and attributes can't have a null value. Instead, simple types (like Integer, Text etc.) have a default value. Integers, Long Integers and Decimals default to 0, Text defaults to the empty string "", Booleans are False. You can also manually change the default value of Attribute, if you don't they get the "default default" value I described above.

Then there's the Null Value property of Input Widgets. If the Variable (or, as is the case with a Form, the Attribute of the Record Variable) had the same value as specified for the Null Value, the Input will be empty (and the Prompt shown). So if the Variable/Attribute is "0" and the Null Value is also "0", you shouldn't see the "0" in the Input.

If that is the case, then when will the null values come into picture?

Hi Neha,

If the value of the bound Variable of an Input is equal to the null value, the Input Widget is empty (safe for the optional Prompt). If it's any other value, that value will be shown.

Kilian Hekhuis wrote:

Hi Neha,

If the value of the bound Variable of an Input is equal to the null value, the Input Widget is empty (safe for the optional Prompt). If it's any other value, that value will be shown.

In my case value of the bound Variable is zero and it is equal to null value. Zero is also a value here. how do I handle this situation?


Hi Neha,

If you have a variable containing 0 (Integer/Decimal) or "0" (Text), and the Null Value Property of the Input is also 0 (or "0"), you shouldn't see a zero in the Input.

Kilian Hekhuis wrote:

Hi Neha,

If you have a variable containing 0 (Integer/Decimal) or "0" (Text), and the Null Value Property of the Input is also 0 (or "0"), you shouldn't see a zero in the Input.


Yes. I am not seeing 0 (Integer/Decimal) but what if I want to make the user see the value as 0?

If you do want the 0 to show, choose another null value, like -1.

Kilian Hekhuis wrote:

Hi Neha,

There's always a record, even if its values are empty. In Outsystems, variables, parameters and attributes can't have a null value. Instead, simple types (like Integer, Text etc.) have a default value. Integers, Long Integers and Decimals default to 0, Text defaults to the empty string "", Booleans are False. You can also manually change the default value of Attribute, if you don't they get the "default default" value I described above.

Then there's the Null Value property of Input Widgets. If the Variable (or, as is the case with a Form, the Attribute of the Record Variable) had the same value as specified for the Null Value, the Input will be empty (and the Prompt shown). So if the Variable/Attribute is "0" and the Null Value is also "0", you shouldn't see the "0" in the Input.

If this is true, then in the casse of date is "1900-01-01" a null value?


Hi Neha,

Yes, but you would use the NullDate() function, not literally "1900-01-01".

Kilian Hekhuis wrote:

Hi Neha,

Yes, but you would use the NullDate() function, not literally "1900-01-01".


Yes I did try that but even in that the Null value of widget is not showing up I still get "1900-01-01" when there is no record.

HI Neha,

If you put NullDate() in the Null Value Property, "1900-01-01" shouldn't show.

Kilian Hekhuis wrote:

HI Neha,

If you put NullDate() in the Null Value Property, "1900-01-01" shouldn't show.

I gave default value as NullDate() so that it shows empty date in the input box and not "1900-01-01" if the record is not present in backend.


Well, that defintely should work. If it doesn't, is there an eSpace that you can share where it doesn't work?

Hello Neha

I think maybe you are not understanding where to set the Null date value...

In the Input widget, there is a property called Null Value. You set this value to NullDate().

Than, if the variable bound to the input has the value Null (1900-01-01), nothing will show up in the input.

Cheers

My usecase is, if there is no record in the DB  i.e NullValue then the value displayed in the input field should be same as the value inside the Null Value property of input widget.

If there is no value in the DB the below value should be displayed.


How do I achieve this?

HI Neha,
instead of setting Null Value of input control try setting up the default value of the variable which is bind to the input control. So until you select a date manually the fefault date will be there.


Regards

-PJ-

Hi Neha,

Some remarks:

  • the format for literal the Date datatype is always #2018-05-15#, no double quotes around it (it's not a String.
  • If you want to display a default value to an input field, you need to assign it yourself, in the Preparation. The Null Value property is used to clear the input when the record you want to display has the same value as the Null Value or, when you submit an empty attribute, to assign to the record the value defined in Null Value.

In your case, you need to, in the Preparation, and after you fetch the record you want to display on the Form, (and regardless of whether you found one or not, there will be a record available on your Aggregate) explicitly check your attribute has NullDate() value and if so, assign to the attribute the value #2018-05-15# .

Hello Neha,

So, what you need is different.
If you have an attribute in an Entity that must have a "default" value, just set the default value in the entity, like this:

In the example above, I want to have the Current Date in the form when there is no information being returned from the database. So, I just set the Default Value of the Attribute Date to CurrDate().

In the form, I don't set the Null VAlue for anything else than the literal NullDate. See bellow:

Now, when I enter in the page, if the aggregate in preparation does not find anything in the database, the input will have the Default value defined in the entity attribute associated:

Cheers.