Hi everybody,
I’m new on SuiteCrm and i’m trying to have an age calculation in a field.
I’m using the last version (7.7).
To do this, i read a lot of doc and posts in the forum and i try this.
First, I have modified the file custom/modules/Contacts/logic_hooks.php like this :
<?php
// Do not store anything in this file that is not part of the array or the hook version. This file will
// be automatically rebuilt in the future.
$hook_version = 1;
$hook_array = Array();
// position, file, function
$hook_array['before_save'] = Array();
$hook_array['before_save'][] = Array(1, 'Contacts push feed', 'modules/Contacts/SugarFeeds/ContactFeed.php','ContactFeed', 'pushFeed');
$hook_array['before_save'][] = Array(77, 'updateGeocodeInfo', 'modules/Contacts/ContactsJjwg_MapsLogicHook.php','ContactsJjwg_MapsLogicHook', 'updateGeocodeInfo');
$hook_array['before_save'][] = Array(1, 'calcul age', 'custom/modules/Contacts/calculage_LogicHook.php','calculageclass', 'calculagefunction');
$hook_array['after_save'] = Array();
$hook_array['after_save'][] = Array(1, 'Update Portal', 'modules/Contacts/updatePortal.php','updatePortal', 'updateUser');
$hook_array['after_save'][] = Array(77, 'updateRelatedMeetingsGeocodeInfo', 'modules/Contacts/ContactsJjwg_MapsLogicHook.php','ContactsJjwg_MapsLogicHook', 'updateRelatedMeetingsGeocodeInfo');
?>
So i only add this line :
$hook_array['before_save'][] = Array(1, 'calcul age', 'custom/modules/Contacts/calculage_LogicHook.php','calculageclass', 'calculagefunction');
After that, i create a new file custom/modules/Contacts/calculage_LogicHook.php and put this inside :
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class calculageclass {
// Local static variable to store your sum
protected static $total = 0;
function functionToSumYourField($bean, $event, $arguments) {
// do any processing and calculations you want before summing your values here
//CALCUL DE L'AGE
//recup anniv
$anniv = $bean->birthdate;
$agecalc = floor(divide(subtract(daysUntil(today()),daysUntil($anniv)),365.242));
//update
$bean->age_c = $agecalc;
$bean->save();
After that, i do a quick repair to test it, but this not works…
The goal is in the contact to have from my field birthdate the calculation of the age of a person in the field age_c.
Can someone help me to understand why this is not working and how to get this working ?
Thanks for the help
Xavier