Peter,
We have a computed field as well in the Accounts module. What we did was rename the Account.php file to Accounts_sugar.php and renamed the class within that file to Accounts_sugar. We then created a new Account.php file with the following contents:
PHP Code:
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once('modules/Accounts/Account_sugar.php');
/** [IC] 20080711 PDB - Extend the Accounts class to modify the save and
retrieve functionality to look at the name_source
column instead of name. */
class Account extends Account_sugar {
var $name_source;
function Account() {
parent::Account_sugar();
}
function retrieve($id = -1, $encode=true) {
$this->field_defs['name_source'] = $this->field_defs['name'];
$this->field_defs['name_source']['name'] = 'name_source';
parent::retrieve($id, $encode);
$this->name = $this->name_source;
return $this;
}
function save($check_notify = FALSE) {
$this->field_defs['name_source'] = $this->field_defs['name'];
$this->field_defs['name_source']['name'] = 'name_source';
$this->name_source = $this->name;
unset($this->field_defs['name']);
return parent::save($check_notify);
}
}
?>
The name column is a computed column. Pretty much what we did was have a different column display the data on the screen (called name_source) so that name_source is saved and not name.
Hope that gives you some ideas.
Bookmarks