Hello and welcome to Variables Default Value Issue.
This Post is meant to explain a ‘Feature’ on the OutSystems 10 and 11 (the ones I tested) platform, where the Default Value of a Variable is lost when moving Entities, or Static Entities from one Module to another.
So, although we know that OutSystems Development Platform is ‘top gun’ we also know that is developed by humans, and humans usually make mistakes.
Today I want to show you that you shouldn’t trust the default value of your variables, when bounding it to other than Basic Data types.
So the scenario is the follow:
Imagine that you are building a ComboBox and you bound this Combo’s Source Entity to a very simple Static Entity
A Person type, and we will assume that there only exists 3 of these, Adult, Child and Baby.
And so, all is good in the kingdom of Outsystems. You Bond the Combo to a variable of the type PersonType Identifier
And change the value of the combo to display the data based on the type of person you selected on that Combo.
So for instance you would have something like this (assuming that you have an entity with PersonType Identifier as an atribute for each PersonType and an Expression below the ComboBox to display the Name of the Person)
Now you bound that Local Variable’s default value to be ‘Adult’ type’, so that each time you enter the page it displays the Adults first.
And you are done with your development. All is working good, months have passed and you got 0 complains about your perfect and complex WebSite.
But today your Boss decides to call you and say, ‘We have done a great job building that website, but it’s somehow slow. As so, we will separate the entities and static entities and put them on another application.’
Like a good lad you do it, unaware about the danger that is coming…
So you start by moving the Entities to the other Application and doing so will, of course, create a ton of errors, because the module doesn’t know where are those entities you are referring to.
But once you manage the dependencies and grab the entities you moved to the new application the errors are automatically corrected because the amazing OutSystems will know that those are the Entities you are looking for. And so the green color of joy will appear…
Publishing it will be a terrible mistake, but you do it anyways.
What happened, you may ask? Here is what, once you moved the entities and you got the errors saying that there isn’t a known Entity to bound your variables and inputs, you lost your default value of your Variable bound to the ComboBox we mentioned in the beginning.
And this ‘Bug’ is a master in disguised because it leaves no errors or warnings.
What will happen is once you access your webpage you will find that you don’t have any adults to display.
But you do have, Hugo was an Adult like we have seen. In fact, if you change your combo box to any other value and change it back to the Adult value you will see Hugo there.
What is happening is, Outsystems will by default bound the variable to its default value, if there isn’t one, it will put the value to null, 0, or something similar. As the variable is bounded to the combobox, and we didn’t specify a specialList value it will display the first record of the static entity ‘Person Type'(the one we used to fill the ComboBox with) which is Adult.
This is a visual error, misleading the user to believe that there aren’t any Adults. But it could be a List of records, it could be a dead end, “if there aren’t any adults, disable combobox”, it could be something way more important than just displaying the adults that we have previously created.
So, in order to avoid this issue, you should always bound your variables, that you want to display straight away in the first load of the page, on the Preparation of the WebPage.
That way you will assure that even if someday you change the structure, entities, or static entities, the value you want to be firstly displayed will always be the same.
Oh, and leave the default values of the variables to Basic Data types 🙂