AnsweredAssumed Answered

before save logic hook gets executed multiple times

Question asked by sidhu sidhu on Apr 14, 2016
Latest reply on Apr 14, 2016 by Bhavesh Patel

Hi All

 

    I have a custom module and i have created an before save logic hook.

But it gets executed multiple times.

 

custom/Extension/modules/P_Projects/Ext/LogicHooks/update_user_following.php

 

<?php

 

$hook_version = 1;

$hook_array = array();

$hook_array['before_save'] = array();

$hook_array['before_save'][] = Array(

 

        //Processing index. For sorting the array.

 

        1,

 

        'P_Projects',  

 

        'custom/modules/P_Projects/update_user.php',

 

        'update_user',

 

        'update_user'

 

    );

 

 

?>

 

 

 

 

 

 

custom/modules/P_Projects/update_user.php

 

<?php

 

 

 

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

 

/**/

 

class update_user{

     function update_user($bean, $event, $arguments){

                

               global $current_user;

            

                    if($bean->fetched_row['name'] != $bean->name)//when name changed

                        {

                   

                        $bean->users_following_c=$bean->users_following_c.",".$current_user->id.",";

                        $bean->save();

                   

                        }

           

          }

 

}

After i changed the name and save the record the users_following_c returns values as ,1,,1,,1,,1,,1,,1,,1,,1,,1,,1,,1, in record view-gets executed multiple times.

Outcomes