AnsweredAssumed Answered

set a field to null in before_save logic hook

Question asked by Steve Cox on Dec 18, 2015
Latest reply on Apr 18, 2018 by André Lopes

Hi,

 

I'm trying to set a previously set field to Null in a Call bean - in the before_save logic hook. However, the previous value always remains.

7.6 Pro.

 

The (simplified)  method in the before_save class is:

 

function setHeldDate($bean, $event, $arguments)

{

   if ($bean->status == 'Held') {

        $bean->mm_calls_held_date_c = $bean->date_start;
   } else {

        $bean->mm_calls_held_date_c = NULL;

   }

}

 

I've confirmed that this runs correctly. If a call is saved and the status is 'Held', then the mm_calls_held_date_c field is set to the start_date. I've also altered the code so that rather than set to null, I've set the mm_calls_held_date_c to '2000-01-01' if not held - and that works.

 

However, when trying to set to null, the previous value always remains. I've tried unset($bean->mm_calls_held_date_c) but that doesn't work.

 

I don't want to user the after_save hook and push it to null - as I'm going to be using the value set in a calculated field in an account roll_up - sothe field needs to be set on the first save.

 

Thanks

Outcomes