SugarCRM SupportDocumentationSugar DeveloperSugar Developer Guide 8.0ArchitectureLogic HooksModule Hooksafter_save

after_save

Overview

The after_save hook executes after a record is saved.

Definition

function after_save($bean, $event, $arguments){}

Arguments

Name Type Description
bean Object The bean object
event String The current event
arguments Array Additional information related to the event (typically empty)
arguments.isUpdate Boolean Whether or not the record is newly created or not. True is an existing record being saved. False is a new record being created
arguments.dataChanges Array A list of the changes in the auditable fields on the bean

Considerations

  • Calling save on the bean in this hook will cause an infinite loop if not handled correctly. (i.e: $bean->save())

Change Log

Version Note
7.0.0RC1 Added dataChanges to the $arguments parameter.
7.0.0RC1 Added isUpdate to the $arguments parameter.
4.5.0c Added after_save hook.

Examples

Creating a Logic Hook using the Extension Framework

./custom/Extension/modules/<module>/Ext/LogicHooks/<file>.php

<?php

    $hook_array['after_save'][] = Array(
        //Processing index. For sorting the array.
        1,

        //Label. A string value to identify the hook.
        'after_save example',

        //The PHP file where your class is located.
        'custom/modules/<module>/after_save_class.php',

        //The class the method is in.
        'after_save_class',

        //The method to call.
        'after_save_method'
    );

?>

./custom/modules/<module>/after_save_class.php

<?php

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

    class after_save_class
    {
        function after_save_method($bean, $event, $arguments)
        {
            //logic
        }
    }

?>

Creating a Core Logic Hook

Prior to Sugar 6.3.x, logic hooks could only be created using the following method. Please note that this approach is still valid but is not recommended when building plugins as it may conflict with existing customizations.

./custom/modules/<module>/logic_hooks.php

<?php

   $hook_version = 1;
   $hook_array = Array();

   $hook_array['after_save'] = Array();
   $hook_array['after_save'][] = Array(
      //Processing index. For sorting the array.
      1, 

      //Label. A string value to identify the hook.
      'after_save example', 

      //The PHP file where your class is located.
      'custom/modules/<module>/after_save_class.php', 

      //The class the method is in.
      'after_save_class', 

      //The method to call.
      'after_save_method' 
   );

?>

./custom/modules/<module>/after_save_class.php

<?php

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

   class after_save_class
   {
      function after_save_method($bean, $event, $arguments)
      {
         //logic
      }
   }

?>

Last modified: 2018-04-26 03:57:24