Using CloudCode, I know I can create records for an audit trail, but is there a way to do so prior to the change being committed? Looking for the equivalent of the .NET event “BeforeUpdate”, and I’d like to avoid performing this from the client if possible
Could you please provide some additional information on what you are looking to accomplish? Are you looking for a webhook that triggers a CloudCode task before the update occurs? Or am I misunderstanding?
That is exactly what I am thinking, wondering it that is possible
There is no current built-in trigger similar to “BeforeUpdate”, the only built in trigger is on persistence to the Cloud DB which is can trigger a
However, as the developer, you have control over what gets saved and when it gets saved when you make updates to the data. In short, you control when you call
.save() on any object in order to persist any changes to the DB. In that way, you can insert whatever logic you want prior to the
.save() statement. Now, webhooks can only be triggered from successful update operations, but you, assuming you have an internet connection, you can call a CC task prior to executing
.save() and pass the “unsaved” object to that function as a parameter. If you don’t have an internet connection then you will have to execute whatever logic you want and capture whatever data you want about the update operation locally on the device / client. Often times developers use the Temporary
LocalDB for this.
For example, if you want to review and compare what has changed before actually saving the record then creating a copy of the record in its original state in
LocalDB can be very useful.
Can you perhaps explain exactly what it is that you want to do, what you want the data to look like and what you want to accomplish with this pre-update audit trail? What behavior are you trying to avoid and what do you expect will be different prior to update vs post update?
Thanks Tielman. Using LocalDB was my backup plan, I was just hoping for a cloud solution to avoid the extra data transfer if possible. It shouldn’t be a big hit though
Please note, data in LocalDB won’t get transferred. So if you want to have an actual audit trail object that gets synched then you will have to store that in a separate model in the DB that does get synched