This SugarCRM logic hook was used to automatically assign leads to users based on status. This mapping was required to help users reassign leads to users such as the “Dead Targets User”. See the logic hook below for the mapping details. In order for this Logic Hook to function the Usernames must exist.
<?php // custom/modules/Leads/logic_hooks.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(); $hook_array['before_save'][] = Array(1, 'Leads push feed', 'modules/Leads/SugarFeeds/LeadFeed.php','LeadFeed', 'pushFeed'); $hook_array['after_save'] = Array(); $hook_array['after_save'][] = Array(1, 'updateAssignedUser', 'custom/modules/Leads/LeadLogicHook.php', 'LeadLogicHook', 'updateAssignedUser'); ?>
<?php
// custom/modules/Leads/LeadLogicHook.php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class LeadLogicHook {
function updateAssignedUser(&$bean, $event, $arguments) {
// Update the assigned user based on the lead's status field.
$status_to_user_map = array(
'Converted' => 'converted',
'Recycled' => 'marketing',
'Dead' => 'deadtargets',
);
if (isset($status_to_user_map[$bean->status])) {
require_once('modules/Users/User.php');
$user = new User();
$user_id = $user->retrieve_user_id($status_to_user_map[$bean->status]);
if(!empty($user_id)) {
$bean->assigned_user_id = $user_id;
$bean->save(FALSE);
if (empty($_REQUEST['massupdate']) && $_REQUEST['module'] == 'Leads' && $_REQUEST['action'] == 'Save' &&
$_REQUEST['return_module'] == 'Leads' && $_REQUEST['return_action'] == 'DetailView') {
SugarApplication::redirect('index.php?module=Leads&action=index');
exit;
}
}
} // if isset
} // end of updateAssignedUser
}
?>
