i have this entity table in my domain
The transactionType attribute used to be a string of size 1
i have changed to be an enumeration with values of W=workout and N=Nutrition
I need to populate the transactiontype attribut to be either W or N
if ConsumedCalories > 0 then TransactionType = ‘W’ else TransactionType = ‘N’
Please advise how to accomplish this.
Make sure you have a backup, but this should be no problem.
There is no fixed link between the enum-type and the value in the database. After you have changed the string to an enumeration, in the database the field type is a CharVar. So if you have access to the database a simple conversion script
UPDATE MyProgressHistory SET TransactionType = “W” WHERE TransactionType = “0”; UPDATE MyProgressHistory SET TransactionType = “N” WHERE TransactionType = “1”
will do, but since we are doing Mendix here I would advise a microflow doing the same. You cannot, however, after changing TransactionType to an enum, do a retrieve from the database with XPath-constraint[ TransactionType = “0”] since the modeler does not allow for an enum-type attribute to get compared to a string.
The easiest Mendix way is to first copy the existing attribute to a copy of itself, so create ‘MyProgressHistory.TransactionTypeOldString’ and create a microflow that copies the string from the original to ~OldString. Run your app and the microflow.
Then change the type of the TransactionType to Enumeration, create a microflow that sets the enumvalue of Transactiontype to what it needs to be based on the ~OldString.
Create the new attribute, keep the old, write some microflow stuff to populate the new one, test, deploy, execute, verify, delete the old attribute, deploy, verify