I’m afraid I can’t think of an easy way to automate this without writing code. However, if you are deleting an account manually then it should be fairly quick to go to the contacts subpanel of the account, select all and delete before you delete the actual account.
If you do want to automate it, then it woludn’t be very difficult to do using a logic hook if you have any experience of coding and customising SuiteCRM.
I want to minimize user error dependency.
But maybe I can create a before_delete logic hook with an SQL query and execute a delete record on the query result.
Any idea on how I can delete ‘by the book’ a record this way ?
I use the method mentioned by mikesolomon. However…if there is a relationship table (ie: relationships added in Studio) the relationship table record is not marked as deleted. I don’t believe this has any effect on SuiteCRM except for bloating the DB as these records wouldn’t get cleaned up.
Looking deeper…this is NOT the way to delete a record. I couldn’t figure out why my before_delete logic hook wasn’t being triggered. The only way the before_delete and after_delete logic hooks will be called is by directly calling the mark_deleted() bean method. When the “deleted” field is marked as true, the logic hooks aren’t fired and the relationships are left alone.
I believe a better solution would be:
$actions = $bean->get_linked_beans ( 'zp_action', 'zp_action' );
foreach ( $actions as $action ) {
$action->marked_deleted($action->id); //<---- This is so the relationships get deleted AND the logic hooks for the $action bean are triggered
$action->Save ();
}
Can’t get this to work.
I’m no expert in this and maybe you can help me.
I have two custom modules:
DLVRY_deployed_services
DLVRY_service_items
with a one-to-many relationship from DLVRY_deployed_services to DLVRY_service_items
I created two files:
custom/modules/DLVRY_deployed_services/logic_hooks.php:
<?php
$hook_version = 1;
$hook_array = Array();
$hook_array['before_delete'] = Array();
$hook_array['before_delete'][] = Array(
//Processing index. For sorting the array.
1,
//Label. A string value to identify the hook.
'before_delete example',
//The PHP file where your class is located.
'custom/modules/dlvry_deployed_services/logic_hooks_class.php',
//The class the method is in.
'logic_hooks_class',
//The method to call.
'before_delete_method'
);
?>
and custom/modules/DLVRY_deployed_services/logic_hooks_class.php:
<?php
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class logic_hooks_class
{
function before_delete_method($bean, $event, $arguments)
{
$actions = $bean->get_linked_beans ( 'DLVRY_service_items');
foreach ( $actions as $action ) {
$action->marked_deleted($action->id); //<---- This is so the relationships get deleted AND the logic hooks for the $action bean are triggered
$action->Save ();
}
}
}
?>
But, when I delete a deployed_service it doesn’t delete the related service items.
I surely am doing something wrong but can’t figure what
Your logic_hooks.php file doesn’t look correct. You need to define a key for the $hook_array sub-array. Also…be careful of the case of your directories if your are on a case-sensitive OS.
It should be:
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
$hook_version = 1;
$hook_array = Array();
$hook_array['before_delete'] = Array();
$hook_array['before_delete'][] = Array(1, 'Some description of the hook here', 'custom/modules/DLVRY_deployed_services/logic_hooks_class.php','logic_hooks_class', 'before_delete_method');
$bean->get_linked_beans ( ‘DLVRY_service_items’); DLVRY_service_items is the bean_name of the field dlvry_deployed_services_dlvry_service_items
which is created when I create the module relationship.
However, changing it to get_linked_beans(‘dlvry_deployed_services_dlvry_service_items’); gives me a blank page when I delete the record and the apache log is this: “Call to undefined method DLVRY_service_items::marked_deleted()…”