Hi all,
Why is OutSystems allowing empty text to an attribute even though the mandatory property is set to yes for the entity attribute? Shouldn't the database throw an empty exception here?
I know this can be achieved via the form1.valid property and enabling built in validation.
My question is if anyone misses to do the form validation, shouldn't the database throw an exception, if the attribute is mandatory in the entity? Any specific reason behind this?
Appreciate your help and guidance here.
Hi @Krishnnambal S ,
there are 2 things here :
1) mandatory on an Outsystems entity <> allow nulls on a database table
so you can't expect the dbms to throw an exception, as far as it is concerned, it is just receiving the default value from the application (a 0 for numerics and an "" for strings for example) and the DBMS is quite happy to store that in the table
2) why is it not enforced by Outsystems
that could be a more valid expectation, the best practices advise to have wrapper actions in place, checking if mandatory attributes do actually have a value, it would maybe be nice if we could have a flag on the entity or entity action call saying that we want it to do that for us
Dorine
PS: I explored making a reusable component doing that, see this for inspiration
Hello Krishnnambal S, I think Dorine covered well your question, but I would like to just make things more explicit.
OutSystems does not have the concept of NULL.That means during runtime, any variables will always have a value. But differently of other programming languages, this value will never be "undefined", even if you didn't defined a default value when declaring the variable. In that case, it will have the default value for the data type, like 0 for integer, emptry string "" for text, etc.
Because of that, whenever the user forgets to add a value to an input bound to an entity attribute marked to be mandatory (in an aggregate or variable of the entity type), and the input is not set to be mandatory or the developer forgets to check the form.valid or activate the validation, the variable itself will still have a value (the default or data type default).
That means the database will never receive NULL, meaning that even if a constraint would be put in place in the database, like Dorine said, it would not raise an exception, because the database IS receiving a value. Like Dorine said, it's a best practice to have your entities set to be READ ONLY in a core module, and create wrappers to provide an api to allow other modules to write to them.It becomes a central point where you can implement server side validations, including validating all required information was provided (and more). This way, if the developer makes a mistake in the interface, your application is safe, because the wrapper will not allow bad data to be saved to the database.Again, this is required, because OutSystems does not have the NULL concept (this is an old discussion, actually).Hope that this may have added to Dorine's Answer.Cheers!
Hi,
Below post may help you on this,
https://www.outsystems.com/forums/discussion/59385/adding-empty-value-even-if-is-mandatory/
https://www.outsystems.com/forums/discussion/57722/input-data-mandatory-field-option-not-working/
Along with that you need to check built in validation is yes or no,
Thanks.
Hi Ajith,
Thanks for your response.
I went through the post yo shared but it doesn't have the answer to my question.
Can you share any snapshot where you are getting this issue, So that other people will aslo able to resolve it.
Hi Ajit,
There is no error here. I am setting the Title attribute of Movie entity as mandatory in the entity.
If I miss to fill a value to the Title field in my form, and if I don't check form1.valid in my logic, the data will get inserted into the database even though I had set the Title field as mandatory.
HI,
I have checked from my end ,
The Is Mandatory option on entities does not enforce validation .
If its empty The default value(datatype ) of that attributes was stored,
ie :
Text = Nulltext
integer, longinteger = 0
Boolean = false ... ext
if you find any answer please LMK .
Hi...be aware with the false empty... like " " (space)
It is not empty but look like.
Hello Krishnnambal ,
Make sure you are using a Form with a record type of the entity you want to create.
If you are just using input and a save button it won't trigger the validation.
Hope it helps!
Paulo Rosário
Hello @Eduardo Jauch , @Dorine Boudry and all,
I am an ODC new starter, I met similar question and while thinking to submit a post, then the forum gave a hint to click into this post. Thank you for the explanations.
The above answers answered most of the confusions, however there is still one piece:
1. In Data tab, for Room table the RoomNumber is set "Is Mandatory" = Yes
2. If review the table data, there is one record with the attribute value empty, which was from validation test. For other records they are all "good" data.
3. Now I try to manually edit the records, I found the behaviors are different: with "good" record, if I leave it blank, I can not save it, got red line warning; however with the "bad” record, I still can leave it empty and save it.
My question: for the two scenarios, shouldn't I get united response, either all accepting bank, or all not?
So this is not about the application, but only about the Service Studio feature to allow editing of the data.
We don't know of course what the exact thinking of the designers was, but I can imagine, when I would design such a thing, that I first check if anything has been changed , and only if so, check on 'mandatory' property.
A setup where you can only save valid values, even if they are already invalid in the database, would make it impossible for a developer to update another field as long as he doesn't fix all other historic invalid data.
Thank you for your reply Dorine!
Yes this is Service Studio feature, I was trying to verify some ODC knowledge by play on it.
I didn't fully get you point of third section, as my question is only regarding one field. But if the meaning is, "when editing on a mandatory record, regardless historically invalid, it should stop the user saving it if still empty", then I totally agree. Does this mean it might be a bug of service studio?
3rd point : the exact opposite : if in entity X, attribute A became mandatory later, and there are still older records where it is empty, and the developer needs to update attribute B, without wanting to fix the historic wrong attribute A, he would not be able to if the mandatory property would be enforced.
But hey, we are all guessing here, it could be that nobody put any thought into this, and it is what it is just by sheer accident.