Re: Calculate Fields

Originally Posted by
xf4driver
Thanks for the prompt reply. Here is my code:
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
$hook_version=1;
$hook_array=Array();
$hook_array['before_save']=Array();
$hook_array['before_save']
[]=Array(1,'calculateField','modules/Line6_LineItems/total.php','Total','calculateField');
?>
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class Total {
function calculateField(&$focus, $event, $arguments) {
$focus->total = $focus->quantity * $focus->price;
}
}
?>
I pretty much copied the example from the referenced thread & plugged in my module & field names.
Try the changes in bold. You are referencing the class TotalClass in your logic hook but then the class is called Total in your script. Also your function within the class needs to be the same. At least this is what looks incorrect to me. I also do the formula differently but this may be a more correct way, so try the changes mentioned first, if it still doesn't work I can show the way I accessed the fields in my script.
Development Setup
Sugar 5.0.0c
Fedora Core 7
Plesk 8.3
PHP 5.2.4-1.fc7
MySQL 5.0.45.fc7
Bookmarks