dataHooks: compare item values before and after update

Question:
How to find out which values (X) changed in my collection item?

Product:
wix crm backend, dataHooks

What are you trying to achieve:
I want to send members an email like “Your project updated on X” whenever a change is made in the collection of the member projects. This could be “invoice added” or “status changed” or both, depending on what was updated.

What have you already tried:
I have two dataHooks inserted affectively (beforeUpdate & afterUpdate) which send out emails just fine, although the beforeUpdate hook is sending emails for testing purposes only. I just don’t know how to compare the item values from beforeUpdate to the ones in afterUpdate, since I cannot call the beforeUpdate function in the afterUpdate hook (doesn’t make any sense).

Do I need a wrapper function of some sort? CanI do this with the hooks?

Just to confirm, the afterUpdate you’re referring to is from afterUpdate - Velo API Reference - Wix.com ?

If so you can compare both the old and new object since context.currentItem contains the pre-update item while item is the post-update item.

Thank you, works perfectly!

1 Like