SugarCRM SupportProduct GuidesSugar DeveloperSugar Developer Guide 11.0ArchitectureSugar LogicUsing Sugar Logic DirectlyUsing Dependencies in Logic Hooks

Using Dependencies in Logic Hooks


Dependencies can not only be executed on the server side but can be useful entirely on the server. For example, you could have a dependency that sets a rating based on a formula defined in a language file.


require_once "include/Expressions/Dependency.php";
require_once "include/Expressions/Trigger.php";
require_once "include/Expressions/Expression/Parser/Parser.php";
require_once "include/Expressions/Actions/ActionFactory.php";

class Update_Account_Hook
    function updateAccount($bean, $event, $args)
        $formula = translate('RATING_FORMULA', 'Accounts');
        $triggerFields = Parser::getFieldsFromExpression($formula);
        $dep = new Dependency('updateRating');
        $dep->setTrigger(new Trigger('true', $triggerFields));
        $dep->addAction(ActionFactory::getNewAction('SetValue', array(
            'target' => 'rating',
            'value' => $formula


Last modified: 2021-02-17 02:44:13