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??)
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
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âŚ
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.