How to reset field values on bean duplication?

sugarcrmdevelopers —  June 14, 2012

SugarCRMWhat you need to do is inject some logic to clear selected field values before the view is displayed.

Like all other stuff made in SugarCRM, this process also depends on what type of module you’re hacking, in other words, the place where you’re going to write the clear logic depends if you’re hacking a custom module or a core one.

Before you perform view customizations on core modules you should always check first if the view is already implemented, in this case, you should check if the following file exists:

modules/<ModuleName>/views/view.edit.php

If so, you should copy it’s logic into the new file which should be written on:

custom/modules/<ModuleName>/views/view.edit.php

and add further customizations.

If you’re hacking a custom module, you are able to choose which directory suits you best, but most of the times you’ll probably want to write it on:

// modules/<ModuleName>/views/view.edit.php

require_once 'include/MVC/View/views/view.edit.php';

class <ModuleName>ViewEdit extends ViewEdit
{
    public function display()
    {
        $this->_processDuplicate();
        parent::display();
    }

    /**
     * How bean will act on edit view when it's being duplicated.
     */
    protected function _processDuplicate()
    {
        if ($this->ev->isDuplicate) {
            $this->bean-><FieldName> = '';
        }
    }
}