before save - discard changes

Hi, I would like to create a before save hook, that will discard all the changes the user has made except for one field.

So somthing like this:

Load bean
$notes = $bean->notes
reset $bean to before changes were made
$bean->notes = $notes

The issue trying to figure out how to reset the bean.

I know how to do this for indiviual fields. using

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

Is there a way of using this logic to restore the whole bean?

I have also tried reloading the bean with

BeanFactory::getBean('Cases', $bean->id);

but it loads the same bean (with the current edits). using this way, i would need a why to tell the bean not to save or to cancel cancel and then reload it.

Any help on eith of my suggestions or any new sufggestions would be great.


Version 7.10.7

Sugar Version 6.5.25 (Build 344)

This is what I will do on the before_save hook:

  1. First you don’t need to load the bean as it is already loaded.
  2. Then I will do a direct query based on the current id and update the only field on the table you want to update.
  3. After running the query, I will redirect the page to list view or to other record that way nothing else is saved on the current bean.


Direct query from LogicHook:

Redirect before save:

Hope it helps,


Thanks, but how do you update a single field before the redirect. If i run $bean->save() it will update all records, if i don’t, nothing will ve saved. How do i just update a single field to the bean?

The onyl way i can think of is using SQL, but this is not ideal, as it will not be capatured in the audit log.


You are right. As I mentioned on my previous post, you can use a query to update the value on the table. Then you can use another query to add the value to the audit table and redirect before save.