Hi there! I’m having trouble deleting a relationship from a record in the “Bugs” module with a security group. This is my before_save hook and I don’t understand why it’s not deleting, as it processes but doesn’t have any action.
<?php
if (!defined('sugarEntry') || !sugarEntry) {
die('Not A Valid Entry Point');
}
class RemoveClass
{
function removeSecurityGroup($bean, $event, $arguments)
{
if ($bean->fetched_row['status'] == 'Assigned' && $bean->status == 'New') {
$bean->load_relationship('SecurityGroups');
$bean->SecurityGroups->delete('3248ee1e-2841-5c8d-6cdd-6446d722fdf9'); //Este es el ID del grupo de seguridad a borrar.
}
}
}
Another thing to consider is that Updating of securitygroups for a bean occurs after the “before_save” logic hook. So maybe it will be better to use an after_save logic hook. And even in the after save logic do a query instead of relationships
For example something like
$bean_id=$bean->id;
$query= "update securitygroups_records set deleted=1 where securitygroup_id='3248ee1e-2841-5c8d-6cdd-6446d722fdf9' and record_id='$bean_id' and module='Bugs'"
Or maybe the relationship name that you use for loading the relationship is wrong? Studio suggests its securitygroups_bugs, but i didn’t test to confirm (the relationship names are strange from time to time, I always have to test first too).