Is there a way to detect change of fields on `afterUpdate` hook?

System Information
  • Strapi Version: 3.4.0
  • Operating System: Mac OS Catalina
  • Database: MongoDB
  • Node Version: 12.18
  • NPM Version:
  • Yarn Version:

Is there a way to detect change of fields on afterUpdate hook?

On after update no. Only inside the beforeUpdate, you can compare the existing value in DB and the value that is passed to update.

1 Like

Hi Sunny, can you give us some sample code to show us how to do this? I’ve built an ecommerce site with a React front end and Strapi backend and I’m needed to check if my client has updated order status. When they update order status, I need to trigger an email. I’m trying to compare the existing order status in the database with a potential change in order status by my client when beforeUpdate runs?

I would recommend you to check out how to customise the update controllers, so you can add your own logic after the update goes through.

Check out the Strapi docs and go to the update method for your collection type below:

Hope this helps :slight_smile:

I found a nice way of doing that with event.state which can be generated in beforeUpdate by simply doing event.state = myState to detect what changed and then sent to afterUpdate. This way you can know what changed and perform operations on the updated object.