Hi all.


As everyone knows, there is a "is Mandatory" property on the each column of the Entity.


What does exactly this property mean?


When I tried to create the new record to a Entity which has some "Is Mandatory yes" column.

When I create the record, I didn't give any value to it. But no DB error has occurred.


What I did are following.

  • Made a Entity type Local variable.
  • give it to the Create action as the source.

When I see the table view after created, it seems like there are default value.

But when it  comes to the text type Value, there are no value in the record.


Q1. When I make the Entity type variable, default value is set automatically?

       If so, the column which requires the text type is set "" as default value?


Q2. Even if the column whose "Is Mandatory" property is "yes" is ""(no value), is it Okay?



Thanks in advance.

Hi, 

The Is Mandatory property of an Entity Attribute is 'meta information'. The database does not know anything about it. 

Where it is used? 

Only in two situations. 

A) when you drag & drop an attribute to a form, a scaffolding is performed and a Label and an Input is placed and configured in the form. The Input, if it has the Mandatory property, will be set with the same value as the Is Mandatory of the attribute. 

B) When saving records to database, if you don't provide a value for an attribute, the default value of the data type or of the attribute will be used. The exception is a Foreign Key. If Is Mandatory is True, a 0 (or "" depending on the data type of the identifier) will be sent if no value is defined. This will probably cause an error if the referenced table does not have an Id equal to 0. If the property Is Mandatory is set to False, it will send NULL ti avoid the error in the database. This is the only time a NULL is sent to OutSystems database (on creating or updating a record). 

Q1. Yes. DatabType default value. 

Q2. If data type is text, yes. 

Cheers 

Eduardo Jauch wrote:

Hi, 

The Is Mandatory property of an Entity Attribute is 'meta information'. The database does not know anything about it. 

Where it is used? 

Only in two situations. 

A) when you drag & drop an attribute to a form, a scaffolding is performed and a Label and an Input is placed and configured in the form. The Input, if it has the Mandatory property, will be set with the same value as the Is Mandatory of the attribute. 

B) When saving records to database, if you don't provide a value for an attribute, the default value of the data type or of the attribute will be used. The exception is a Foreign Key. If Is Mandatory is True, a 0 (or "" depending on the data type of the identifier) will be sent if no value is defined. This will probably cause an error if the referenced table does not have an Id equal to 0. If the property Is Mandatory is set to False, it will send NULL ti avoid the error in the database. This is the only time a NULL is sent to OutSystems database (on creating or updating a record). 

Q1. Yes. DatabType default value. 

Q2. If data type is text, yes. 

Cheers 

Thank you for your reply.


>The exception is a Foreign Key. If Is Mandatory is True, a 0 (or "" depending on the data type of the identifier) >will be sent if no value is defined. This will probably cause an error if the referenced table does not have an Id >equal to 0.


I'm sorry but I didn't really get this part...

You mean if the attribute is set "Is Mandatory True"  and set as external key, the exception is thrown(In the case that id equals to 0)?

 Regards.



Solution

Hi, 

You are working with relational database. 

If your record has a foreign key (fk) and you oass anything different than NULL for this attrubute, database will check if the id is valid in the referenced entity. If it does not find a valid record for this id, it throws an error. 

For example, your rrecord has a UserId attrubute. If younset it to Is Mandatory = True, when saving to database, if you don't provide a value of a user identifier, platform will send 0.

But as the User table in database has an id that is autonumber starting in 1, it will not find anything and will throw the exception. 

If you set the UserId with Is Mandatory = False, when saving a record without providing a user identifier, the olatform will send NULL, so the database does not complain.

But this is valid only for Foreign Keys. Other attributes thebolatform will send the attribute default value or the attribute data type default value. 

Cheers 

Solution

Eduardo Jauch wrote:

Hi, 

You are working with relational database. 

If your record has a foreign key (fk) and you oass anything different than NULL for this attrubute, database will check if the id is valid in the referenced entity. If it does not find a valid record for this id, it throws an error. 

For example, your rrecord has a UserId attrubute. If younset it to Is Mandatory = True, when saving to database, if you don't provide a value of a user identifier, platform will send 0.

But as the User table in database has an id that is autonumber starting in 1, it will not find anything and will throw the exception. 

If you set the UserId with Is Mandatory = False, when saving a record without providing a user identifier, the olatform will send NULL, so the database does not complain.

But this is valid only for Foreign Keys. Other attributes thebolatform will send the attribute default value or the attribute data type default value. 

Cheers 

Thank you very much!

I totally got waht you mean.


Best Regards.