Trigger Custom Code on Field Change/Update

Is there any way to trigger custom code with the change of a given field in a record.

I have a model for running Logic Hooks on a “Record” update (before_save), that allows me to run some custom code and inject results into the bean before it gets saved into the Dbase, but I have a new use case where I ONLY want to run a certain function when a specific field is updated, not ‘every’ time the record is saved, but rather ONLY IF the field is updated.

I can think of a way to do this perhaps like this:

  • Trigger the Before Save logic hook
  • lookup the record that’s being saved in the Dbase
  • compare the specific field I’m focused on to the value in the Dbase
  • IF NOT a match, run my custom code
  • etc…

But it seems like this might be easier to do???
Is there a better way??

Is it possible to trigger custom code via workflow?? (and watch for the field update there, instead??)

Thoughts???

Thanks all!!

If I understand correctly, the piece of the puzzle that you’re missing is fetched_row which you can use inside the hook to inspect what were the values before.

Here is an example, and you’ll find more if you need them

Ooooooooo…
This does sound interesting…!!!
Might be the thing I’m looking for!
Will experiment…thanks!

I guess this solution is interesting, but it ‘does’ require that I query the Dbase ‘mid stream’, and compare the values of what I’m sending, to the values that are in the Dbase…

This is ‘ok’…but I guess I was wondering if there was any way to ‘trigger’ some custom code “only” when the specific field (in this case phone_mobile) has ‘changed’ or is updated.

I see triggers for this type of thing in “Workflow”, but it seems you can’t trigger custom code from a Workflow…

Does that make sense??
Any thoughts??

There is no way of only triggering custom code on a specific field change.

But don’t think that there is a performance penalty for looking at fetched_row. You’re not actually querying the database, all that data is already there in every logic hook, whether you look at it or not.

Don’t be afraid to use this solution, it’s perfectly standard and works well.

Great. Thanks!
I was trying to ‘save’ the additional Dbase hit…this might be a winning strategy.

Yep - I’m all good!
Got it working!

Thanks a million!!!

1 Like