Hi there
Lets see if you can give me a hand here. I am trying to set up a before_save logic hook for one of my custom modules. Have followed the instructions in the wiki (I think correctly) but dont get the process to work.
Let me explain you the situation, In my custom module, what I want to get is sugar to check, before the record is saved, if ,when two specific values, of two dropdown files, are selected to check if a third text value is null.
If so an alert message should appear, and if not the record should be saved.
To get this Ihave created a logic_hook.php file in custom/modules/Pacie_Pacientes/ whith this content
Then I have created a php field called Comprobaciones.php in also custom/modules/Pacie_Pacientes/ with this codePHP Code:<?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(1, 'Pacientes', 'custom/modules/Pacie_Pacientes/Comprobaciones.php','Comprobaciones', 'Comprobaciones');
?>
Could you please let me know why I dont get this logic hook to work??PHP Code:<?PHP
/********************************************************************************/
/**
* THIS CLASS IS FOR DEVELOPERS TO MAKE CUSTOMIZATIONS IN
*/
class Comprobaciones {
function Comprobaciones(&$bean, $event, $arguments) {
// This funtion will check for records with field "estado" with value "Terminado" and field "respuesta" has value "Positiva", then
// the field "coste_expediente" Cannot be null
// if so the record will be saved correctly, if not an alert message should be shown.
//
if($bean->estado == 'Terminado'){
if($bean->respuesta == 'Positiva'){$bean->CheckCoste($bean, $event);}
}else {parent::save($event);}
}
// CheckCoste will check if the field is null or not, if it is an alert message should be shown and the record //must not be saved
//
function CheckCoste(&$bean, $event){
if($bean->coste_expediente == '')
{
// Alert message
alert("Coste field should not be empty, please add the right value before saving.");
}
else
{parent::save($event);}
}
}
?>
Thanks a lot
Edit/Delete Message


LinkBack URL
About LinkBacks



Reply With Quote

Bookmarks