Hi,
I added to project a new text-field “project_number_c”.
In contract I added a relationship-field “projekt_c”, where I select the project. After the selection, I want to display the project-number too, so I added a text-field “projektnummer_c” to contract.
I added to the folder “\custom\modules\AOS_Contracts” two files: logic_hooks.php
<?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['before_save'][] = Array(
//Processing index. For sorting the array.
1,
//Label. A string value to identify the hook.
'before_save example',
//The PHP file where your class is located.
'custom/modules/AOS_Contracts/before_save_class.php',
//The class the method is in.
'before_save_class',
//The method to call.
'before_save_method'
);
?>
and before_save_class.php
<?php
//if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class before_save_class
{
function before_save_method($bean, $event, $arguments)
{
//lets assume the account field in deliveries is account_id_c
//We will use beans to fetch the related account's details
$project = new Project();
$project->retrieve($bean->project);
//Set the values from accounts into deliveries
// $bean is your current record being saved.
// $account is the related account.
$bean->projektnummer_c = $project->project_number_c;
//Same stuff in order to set other values
}
}
//}
?>
But I think the retrieve-line fails, because just the default-value of the project number is displayed and not the number of the selected project.
What is wrong?
<?php
//if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class before_save_class
{
function before_save_method($bean, $event, $arguments)
{
//lets assume the account field in deliveries is account_id_c
//We will use beans to fetch the related account's details
$project = new Project();
$project->retrieve_by_string_fields(array('name' => $bean->projekt_c ));
//Set the values from accounts into deliveries
// $bean is your current record being saved.
// $account is the related account.
$bean->projektnummer_c = $project->project_number_c;
//Same stuff in order to set other values
}
}
//}
?>