Validation in before_save

Hello.

Unfortunately, the changes you have suggested don’t appear to have any effect. My hook code is:


<?php

if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

class WFAU1_ValidateBeforeSave {

    function validateBeforeSave ($bean, $event, $arguments) {
        $GLOBALS['log']->debug('WFAU1_ValidateBeforeSave: Start'); 

        if (is_null($bean->id)) {
            $beanList = $bean->get_list(
                                'wfau1_wmsaccount.name', // order
                                "wfau1_wmsaccount.name = '" . $bean->name ."'",
                                0, // offset
                                1 // max items
            );
        } else {
            $beanList = $bean->get_list(
                                'wfau1_wmsaccount.name', // order
                                "wfau1_wmsaccount.name = '" . $bean->name ."' and wfau1_wmsaccount.id != '" . $bean->id . "'",
                                0, // offset
                                1 // max items
            );
        }

        if ($beanList['row_count']>0) {
            $GLOBALS['log']->debug('WFAU1_ValidateBeforeSave: Duplicate found'); 
            SugarApplication::appendErrorMessage('Duplicate account id');
            SugarApplication::redirect("index.php?module=&action=EditView");
        }

        $GLOBALS['log']->debug('WFAU1_ValidateBeforeSave: End'); 

    }
}

I have attached pictures showing what I am doing. In step 1, I am viewing an Account record and have gone to the sub-panel for my custom module.

In step 2, I have clicked on the “Create” button to bring up the quick create form.

If I enter a duplicate account id, and click “Save”, I get taken back to the same sub-panel as in step 1, showing only a single record but no error message.

Regards,

Carl