Hi,

I am trying to create a price history in database. I have 2 entities "price" and "price history".

When users input a certain price (in a form), it will create a record in the "price" entity. Whenever they edit the prices, the record in the "price" entity will be updated. However, i want to keep the record of the old price in the "price history" entity. I am having having troubles assigning the variables in the "save" button for my form. Can someone help to see where the problem lies?

There are different solutions to this problem.


One is to have two tables as you have:

- Prices

- Price History


Then in the tables, I advise you to have the following fields, in addition to the ones you need:

- CreateBy

- CreateAt

- UpdateBy

- UpdateAt


And these 4 attributes must be filled in all CRUD actions in the Prices table.


In your CRUD actions on the Prices table:

- CreateOrUpdate

- Update

- Delete

... here you have to understand what makes sense to you ... again, this is just a solution, there are several, and I am describing it in a generic way, which you then have to adapt to your reality.


... In these CRUD actions in the Prices table, for example in Update, every time you call the Update function of the Prices table, in its logic, before you update the table, you create with the data in this line to the Price History table.


Do you think I could help you?


Cheers,
Nuno

Nuno Miguel Verdasca wrote:

There are different solutions to this problem.


One is to have two tables as you have:

- Prices

- Price History


Then in the tables, I advise you to have the following fields, in addition to the ones you need:

- CreateBy

- CreateAt

- UpdateBy

- UpdateAt


And these 4 attributes must be filled in all CRUD actions in the Prices table.


In your CRUD actions on the Prices table:

- CreateOrUpdate

- Update

- Delete

... here you have to understand what makes sense to you ... again, this is just a solution, there are several, and I am describing it in a generic way, which you then have to adapt to your reality.


... In these CRUD actions in the Prices table, for example in Update, every time you call the Update function of the Prices table, in its logic, before you update the table, you create with the data in this line to the Price History table.


Do you think I could help you?


Cheers,
Nuno

Hi Nuno,

Referring to your last paragraph, i tried to create a new line to the price history table, however, when i check the price history database, the record is there but the data is zero. So i believe my assignment of variables is wrong. 


Hi Jolene,

Adding to what Nuno suggested/advised. A small contribution from my side.


After referring the shared .oml solution. Below are my observations.


1) The define Data Model is not appropriate.

2) Re-framed the data model and relationships:

PFA - Includes the solution after some code changes. Watch out the save button action flow as well.


Hope this helps you!


Regards,

Benjith Sam

Yes, if the creation of the entry in the database is there, only that you have empty data, it is because you may be doing the incorrect assignment.


Try a little to work on it, if you can't, share with me what you're doing.

Hi Jolene,

thank you for uploading your .oml example. The error I saw was "OSUSR_0W2_PRICE with key 0 was not updated".

The issue is the SaveOnClick action is calling UpdatePrice with a new record.  Try using CreatePrice or CreateOrUpdatePrice.

I would recommend you create a server action passing the relevant entities and call entity create or update actions on the server side.  There are some great tutorials that will walk you through creating mobile applications and synchronising data from device to server.

Try this one https://www.outsystems.com/learn/paths/1/becoming-a-mobile-developer/

Also the above suggestions make a good point about considering your entity model.

I hope this helps!

Kind regards,

Stuart

Benjith Sam wrote:

Hi Jolene,

Adding to what Nuno suggested/advised. A small contribution from my side.


After referring the shared .oml solution. Below are my observations.


1) The define Data Model is not appropriate.

2) Re-framed the data model and relationships:

PFA - Includes the solution after some code changes. Watch out the save button action flow as well.


Hope this helps you!


Regards,

Benjith Sam

Hi Benjith,

Thanks for the suggestion on my entity model. 

I tried the oml that you edited but it doesnt work, as no price history is being created in the database after i press the save button. 



Processing Upload...

Hi Jolene,

Sorry for the late reply. Please find the solution .OML attached file for your reference.


Check this: Sample Application Link


Let me know if you have any doubts in the implemented code. Hope this helps you!


Regards,

Benjith Sam

Solution

Hi Jolene,


PFA.


Regards,

Benjith Sam

Solution

Benjith Sam wrote:

Hi Jolene,


PFA.


Regards,

Benjith Sam

Hi Benjith,

Thank you so much for your oml ! I was stuck at this issue for quite a while. 


Jolene Kwek wrote:

Benjith Sam wrote:

Hi Jolene,


PFA.


Regards,

Benjith Sam

Hi Benjith,

Thank you so much for your oml ! I was stuck at this issue for quite a while. 



Hi Jolene,

I'm glad that I could be your help.


Regards,

Benjith Sam