Topic: Populate an history table on action "save"

Do you think it would possible to populate an history table on action "save" or "delete"?

For example:

Each time I insert, edit or delete a record, I would like to get the modification logged with the date in a separate table when clicking on "Save" or "Delete"

Re: Populate an history table on action "save"

It is possible, but maybe it will be a little difficult.


Please, download example project:

Post's attachments

Attachment icon Employees logs.zip 8.47 kb, 899 downloads since 2014-11-24 

Dmitry.

Re: Populate an history table on action "save"

Thanks a lot for super fast reply. Being very busy at the moment, I have no time to try it but I will do as soon as I have some spare time.

I quickly looked into your example and everything is based on scripts. Would it be possible to get any kind of documentation about the script features? (functions, how to use them, etc...) That would be very helpful especially if you want to sell you application to companies.

Re: Populate an history table on action "save"

At the moment there is no documentation about script, because used popular programming language "ObjectPascal", you can read any book about Delphi.


But documentation is planned.

Dmitry.

Re: Populate an history table on action "save"

I spent some time to look how the script works, I am still struggling in logging the last 2 columns (birthdate and ID) when deleting a line. I would prefer to log all the information contained in a row, but I did not understand how to manage it.

An explanation would be more than welcome smile

Re: Populate an history table on action "save"

tcoton
added it to the project, please download again
http://myvisualdatabase.com/forum/misc. … download=1

Dmitry.

Re: Populate an history table on action "save"

Wow, it is more complex than I thought.

It works now but when I create a new record, the ID is logged as -1 instead of current ID smile

Re: Populate an history table on action "save"

tcoton wrote:

Wow, it is more complex than I thought.

It works now but when I create a new record, the ID is logged as -1 instead of current ID smile

Checked, current ID also logged, please, send me screenshot, where you find -1 ?

Dmitry.

9 (edited by tcoton 2014-12-01 14:23:33)

Re: Populate an history table on action "save"

Do you think it would be possible to capture the Windows user login to log who performed changes in the database?

Re: Populate an history table on action "save"

tcoton wrote:

Do you think it would be possible to capture the Windows user login to log who performed changes in the database?

Yes, you can get user name using function GetUserName


example:

ShowMessage(GetUserName);
Dmitry.

Re: Populate an history table on action "save"

Ok, great but I am not a developer as for almost all your users, how can I implement that with the employee log database?

Re: Populate an history table on action "save"

I  made example for you:

Post's attachments

Attachment icon Employees logs with GetUserName.zip 8.65 kb, 826 downloads since 2014-12-02 

Dmitry.

Re: Populate an history table on action "save"

It works great, thanks a lot for fast reply!

Now I will learn how to implement everything into my own db smile

Re: Populate an history table on action "save"

What is the correct syntax to put comments in the code? I would like to make the script easy to understand as per good practice.

Re: Populate an history table on action "save"

// comments
ShowMessage('Hello'); // comments
Dmitry.

Re: Populate an history table on action "save"

The script is now mature, if somebody is interested, I could write a document and submit it to the Author of MVDB for implementation in the official documentation.