63
Views
8
Comments
About the default value of Database
Question
Application Type
Reactive

Hi, all

About DB flag, I want to define it as follows,

1 -> ON,
other -> OFF

However, I have some concerns because OutSystems does not accept NULL.

Should I set a default value for something that is set to 0 in the DB definition?
But it requires a lot of work, I guess.

DB-wise, if nothing is set, it will be NULL but OutSystems does not identify NULL value.

What are the best practices?

Regards,

Sammy

2025-02-21 07-07-34
Rishabh Tailor

Hi, @Sammy A ,

As I can understand your requirement, you want a boolean variable that will be set to "true"/1 for some conditions and "false"/0 in other conditions.

So if you create an attribute in an entity and define it's datatype as boolean and it is non-mandatory, then it will be by default false if you don't assign it explicitly.

If you want to consider three values: null, False and True, then you can follow the approach mentioned by Daniel Kuhlmann in the reply to the following question: 

https://www.outsystems.com/forums/discussion/55071/how-can-i-get-null-booleans-into-an-outgoing-payload/

For exploring more about Default, follow the documentation further from this link. 

https://success.outsystems.com/documentation/11/reference/outsystems_language/data/database_reference/default_values_on_database/


I hope this addresses and clears up your question.

2022-12-30 09-46-57
Deepika Patel

Hi @Sammy A,

For this you can use Boolean Fields:

  • If the flag represents a binary state, consider using a boolean field in OutSystems. In OutSystems, a boolean field can naturally represent ON and OFF states (True and False).
  • Map this boolean field to your database column, where True corresponds to 1 and False corresponds to 0, set the default value to 0 (OFF) .

Hope this helps!

Regards,

Deepika

UserImage.jpg
Masugorou A

Hi @Deepika Patel

I appreciate your kind supoprt.

I have a question.
What exactly does a boolean field mean.

Regards,

Sammy

2024-06-30 04-29-36
Priya Jhode

Hello, @Sammy A 

This post will helps you. please check 

https://www.outsystems.com/forums/discussion/42152/null-is-not-0-os-drawback/#Post154494

Best Regards,

-- Priya Jhode

2021-11-12 04-59-31
Manikandan Sambasivam

If the flag is meant to be a simple ON/OFF switch, use the Boolean data type in OutSystems to avoid the complexity of handling NULL values. If you must work with a column that can be NULL, ensure your logic correctly handles NULL values. However, it’s generally better to avoid NULLs for boolean flags by using default values. 

2024-06-08 15-17-54
Nawaz Khan

for Null values in DB, OutSystems responds as following in the Outsystems environment.

Null text in DB is considered as empty string or ''

Null Number (integer, long integer etc) in DB is considered as 0

Null Boolean in DB considered as false

Null Date or Datetime in DB considered as '1900-01-01'

Boolean values used with fields can have only two possible states like (true/false, active/inactive etc). If your requirement is to have three values (true, false and null) then better to use lookup table and link the lookup table Ids with your main table. in this way you have the appropriate values and the text as well which you want to display to user in case of Null (Others, Not selected, N/A etc)

Hope this Resolve your issue

UserImage.jpg
Masugorou A

Hi, all

What will happen in external DB situation?

Will external DB defaults prioritize?


Regards,

Sammy

2024-06-08 15-17-54
Nawaz Khan

@Sammy A, in external DB situation the Outsystems behavior will remain same as I described earlier.

Hope this will help

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.