Get public value beforesave

Hi all,
i need to compare the value of a field before and after user modification.
The variable containing the “before” value must be accessible in the logichook after_save.

I tried to set a “public” variable in the class and fill it in before_save_method but it seems this doesn’t work.
Any suggestions? Thanks.

Hi,
you can simply compare

$bean->your_field_c === $bean->fetched_row['your_field_c']

The second value is the “old” value derived from the db, the first one might have been changed by an user.

Thanks!
This, I guess in before_save.

But how do I get the “true” or “false” (ie, equal or not) state in after_save?

Hi,
assuming this is the class/method mentioned in your hook registration:

class MyHookClass {
    function myFunction($bean, $event, $arguments){
      if($bean->your_field_c !== $bean->fetched_row['your_field_c']){
        //execute your code here -> field has changed
      } else {
       //some other code
      }
   }
}

E: this should work for after_save directly.
E2: typo, I replaced === with !==

2 Likes
  1. you can add some field for the Object Bean in before_save hook set

example

$bean->your_field_c_chenge = true;

and check this value in the hook after_save.

if(isset($bean->your_field_c_chenge) & $bean->your_field_c_chenge  === true)
1 Like