75
Views
16
Comments
Solved
How To Store Past Data In History Table and The Updated Data In The Main Table.
Question

We have a master table in which we are creating a record and it is getting stored in the same table .

if we update the particular data the updated data will get saved in the table  but we want the past data of that record to get  saved in different table ( History Table).

2023-05-23 04-55-55
Wasimkhan Syed Abuthahir
Solution

Hi,

In the OnAfterFetch, store the current data in local variable.

and when the data gets updated. compare it with local variable. If the value differs, Create a record in history table.




This is one of the way to achieve your requirement.


Regards,
Wasimkhan S

2021-09-06 15-09-53
Dorine Boudry
 
MVP

this is logic that should typically go into either a CRUD wrapper, or a server side business logic, not on client side.

2023-05-23 04-55-55
Wasimkhan Syed Abuthahir
2021-09-06 15-09-53
Dorine Boudry
 
MVP

yes, 

that is already better (at least you have transactionality and you only go to server once)

but I would say:

  • if you feel like first checking if something really changed, then don't drag along a local variable that you somehow created on client side, just read the record from database again at start of server action, and check against those values.  
  • if you go through the trouble of first checking if anything changed, then why only put the CreateHistoryRecord in the True path, why would you still do the CreateOrUpdate itself if nothing changed ?

Dorine

UserImage.jpg
Katie Midge

Hi @Wasim Khan, I am a beginner in Outsystems and I tried implementing your logic into my app however it's not saving anything in my history table. Do you have an OML which I could refer to? Thank you very much.

2023-05-23 04-55-55
Wasimkhan Syed Abuthahir

Hi @Katie Midge ,

I dont have OML for this. Pls check you have assigned the values correctly.


Regards,
Wasimkhan S

2023-11-20 06-53-17
Neha Rathore

Hello Prachiti,

Here's a suggestion for storing past data: Before updating new data, check if the data already exists using its ID. If it does, create or update a History table with that data, and then update the data in the existing table.

I hope this explanation helps you understand the process better.

Let me know if you have any further questions.

Thanks

2024-12-10 04-40-04
Gitansh Anand

Hi @PRACHITI THOMBARE, There are two ways: first, when you are creating or updating anything in the main table, make an entry in the history table right after that. For this, you can call the insert wrapper of history in the main table's crud wrapper. In this case, the values of the last entry in the history table will be the same as the main table values. For the second method, in the insert wrapper of the history table, fetch the latest record of the main table and insert it in the history table, then in the main table's update wrapper, first call the insert wrapper of the history table, then make the entry in the main table.

Thanks
Gitansh Anand

2022-07-14 13-58-54
Ridhima Shewani

Hi @PRACHITI THOMBARE,


Do you want to add record in history table only once or whenever you update any record changes will capture in history table and updated one is remain in main table? 

Thanks

Ridhima

UserImage.jpg
Bhagyashri More

yes correct.


UserImage.jpg
Bhagyashri More

Yes.. Every time when we update the data ,the updated data will get save in the main table but the past record should get saved in the history table . 


2023-05-23 04-55-55
Wasimkhan Syed Abuthahir
Solution

Hi,

In the OnAfterFetch, store the current data in local variable.

and when the data gets updated. compare it with local variable. If the value differs, Create a record in history table.




This is one of the way to achieve your requirement.


Regards,
Wasimkhan S

2021-09-06 15-09-53
Dorine Boudry
 
MVP

this is logic that should typically go into either a CRUD wrapper, or a server side business logic, not on client side.

2023-05-23 04-55-55
Wasimkhan Syed Abuthahir
2021-09-06 15-09-53
Dorine Boudry
 
MVP

yes, 

that is already better (at least you have transactionality and you only go to server once)

but I would say:

  • if you feel like first checking if something really changed, then don't drag along a local variable that you somehow created on client side, just read the record from database again at start of server action, and check against those values.  
  • if you go through the trouble of first checking if anything changed, then why only put the CreateHistoryRecord in the True path, why would you still do the CreateOrUpdate itself if nothing changed ?

Dorine

UserImage.jpg
Katie Midge

Hi @Wasim Khan, I am a beginner in Outsystems and I tried implementing your logic into my app however it's not saving anything in my history table. Do you have an OML which I could refer to? Thank you very much.

2023-05-23 04-55-55
Wasimkhan Syed Abuthahir

Hi @Katie Midge ,

I dont have OML for this. Pls check you have assigned the values correctly.


Regards,
Wasimkhan S

UserImage.jpg
Aishvarya Yadav

Hello @Wasim Khan 

What is Check form data?

2023-05-23 04-55-55
Wasimkhan Syed Abuthahir

The data which was captured in OnAfterFetch.


UserImage.jpg
Bhagyashri More

Hello @Wasim Khan 

the data that is getting saved in history table is the updated one , we want to save Past data.


UserImage.jpg
PRACHITI THOMBARE

Hello @Wasim Khan 

Thankyou ... 

Resolved . 

2023-05-23 04-55-55
Wasimkhan Syed Abuthahir

Good to hear. Thanks. You can mark the solution if your issue resolved.


Regards,

Wasimkhan S

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.