Yes, you can do this.
This is where I learned: http://www.sugarcrm.com/wiki/index.p...l_custom_logic
But for you specifically, in your custom/modules/Opportunities folder, you will need to add this to your logic_hooks.php file:
PHP Code:
$hook_array['before_save'][] = Array(2, 'actionName', 'custom/modules/Opportunities/Opportunities_cstm.php','Opportunities_cstm','checkOpportunityStatus');
(The above should be on a single line, and for some reason there is an odd space between the 'c' and 'k' in 'checkOpportunityStatus'.)
The above code tells Sugar to execute the checkOpportunityStatus function in the Opportunities_cstm object located in the custom/modules/Opportunities/Opportunities_cstm.php file just before an Opportunity record is saved to the database.
Now you will need to create the Opportunities_cstm.php file and place it in your custom/modules/Opportunities directory. This is what should be in the file:
PHP Code:
define('sugarEntry',TRUE);
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class Opportunities_cstm {
function checkOpportunityStatus(&$bean, $event, $arguments) {
if ($_REQUEST['status']=='Won') {
$bean->new_amount_standing = $_REQUEST['amount'];
}
}
}
I havne't tested this code, but it should be a start. Please post back with any questions.
Other Sugar developers, please let me know if this is not the proper way to do this. Thanks.
Bookmarks