assigned_user_id 不变
assigned_user_id doesn't change
肯定是简单的东西,但我只是没看到。
我有一个 before 和 after 保存挂钩,它们只是检查分配的用户 ID 是否已更改。但是我在之前和之后的保存挂钩中得到了相同的 user_ID。
Logic Hook 注册表
$hook_array['before_save'] = Array();
$hook_array['before_save'][] = Array(
77,
'If a new user is assigned to the unit of inventory it changes inventory status to OFFER',
'custom/modules/un_inventory/user_assigned_c.php',
'user_assigned_c',
'user_assigned_before_save');
$hook_array['after_save'] = Array();
$hook_array['after_save'][] = Array(
78,
'If a new user is assigned to the unit of inventory it changes inventory status to OFFER',
'custom/modules/un_inventory/user_assigned_c.php',
'user_assigned_c',
'user_assigned_after_save');
和逻辑挂钩
class user_assigned_c {
function user_assigned_before_save($bean, $event, $arguments) {
$GLOBALS['log']->info('User ID before save: '.$bean->assigned_user_id);
}
function user_assigned_after_save($bean, $event, $arguments) {
// $bean->assigned_user_id stays the same as in the method above...
$GLOBALS['log']->info('User ID after save: '.$bean->assigned_user_id);
}
}
这是意料之中的。通常的流程可能如下:
$bean = getBeanFromSomewhere();
$bean->assigned_user_is = "12345ABC";
$bean->save();
请注意,在保存中已设置分配的用户 ID。
如果你想检查钩子中某物的先前值是什么,你可以使用 fetched_row
属性 - 它存储加载 bean 时的字段列表。
即
$newId = $bean->assigned_user_id;
$oldId = $bean->fetched_row['assigned_user_id'];
if($newId !== $oldId){
//Assigned user changed!
}
我认为过去 fetched_row
在保存后挂钩中存在问题,但希望以上内容有所帮助。
在 SugarCRM 7+ 中,您可以使用 after_save
挂钩:
function user_assigned_after_save($bean, $event, $arguments) {
if (!$arguments['isUpdate']) {
$GLOBALS['log']->info('New bean with User ID: '.$bean->assigned_user_id);
} else if (isset($arguments['dataChanges']['assigned_user_id'])) {
$idChange = $arguments['dataChanges']['assigned_user_id'];
$old = $idChange['before'];
$new = $idChange['after'];
$GLOBALS['log']->info("Bean's User ID was changed from '$old' to '$new'");
}
}
在 SugarCRM(新旧版本)中,还有 SuiteCRM,
您可以使用 before_save
挂钩(如 Jim 所述):
function user_assigned_before_save($bean, $event, $arguments) {
$old = $bean->fetched_row['assigned_user_id'];
$new = $bean->assigned_user_id;
if ($old != $new) {
$GLOBALS['log']->info("Bean's User ID was changed from '$old' to '$new'");
}
}
如果您使用 before_save
挂钩并且您有修改 assigned_user_id 字段的挂钩,请确保这些挂钩 运行 的顺序正确(挂钩数组中的第一个参数每个挂钩定义顺序)。
肯定是简单的东西,但我只是没看到。
我有一个 before 和 after 保存挂钩,它们只是检查分配的用户 ID 是否已更改。但是我在之前和之后的保存挂钩中得到了相同的 user_ID。
Logic Hook 注册表
$hook_array['before_save'] = Array();
$hook_array['before_save'][] = Array(
77,
'If a new user is assigned to the unit of inventory it changes inventory status to OFFER',
'custom/modules/un_inventory/user_assigned_c.php',
'user_assigned_c',
'user_assigned_before_save');
$hook_array['after_save'] = Array();
$hook_array['after_save'][] = Array(
78,
'If a new user is assigned to the unit of inventory it changes inventory status to OFFER',
'custom/modules/un_inventory/user_assigned_c.php',
'user_assigned_c',
'user_assigned_after_save');
和逻辑挂钩
class user_assigned_c {
function user_assigned_before_save($bean, $event, $arguments) {
$GLOBALS['log']->info('User ID before save: '.$bean->assigned_user_id);
}
function user_assigned_after_save($bean, $event, $arguments) {
// $bean->assigned_user_id stays the same as in the method above...
$GLOBALS['log']->info('User ID after save: '.$bean->assigned_user_id);
}
}
这是意料之中的。通常的流程可能如下:
$bean = getBeanFromSomewhere();
$bean->assigned_user_is = "12345ABC";
$bean->save();
请注意,在保存中已设置分配的用户 ID。
如果你想检查钩子中某物的先前值是什么,你可以使用 fetched_row
属性 - 它存储加载 bean 时的字段列表。
即
$newId = $bean->assigned_user_id;
$oldId = $bean->fetched_row['assigned_user_id'];
if($newId !== $oldId){
//Assigned user changed!
}
我认为过去 fetched_row
在保存后挂钩中存在问题,但希望以上内容有所帮助。
在 SugarCRM 7+ 中,您可以使用 after_save
挂钩:
function user_assigned_after_save($bean, $event, $arguments) {
if (!$arguments['isUpdate']) {
$GLOBALS['log']->info('New bean with User ID: '.$bean->assigned_user_id);
} else if (isset($arguments['dataChanges']['assigned_user_id'])) {
$idChange = $arguments['dataChanges']['assigned_user_id'];
$old = $idChange['before'];
$new = $idChange['after'];
$GLOBALS['log']->info("Bean's User ID was changed from '$old' to '$new'");
}
}
在 SugarCRM(新旧版本)中,还有 SuiteCRM,
您可以使用 before_save
挂钩(如 Jim 所述):
function user_assigned_before_save($bean, $event, $arguments) {
$old = $bean->fetched_row['assigned_user_id'];
$new = $bean->assigned_user_id;
if ($old != $new) {
$GLOBALS['log']->info("Bean's User ID was changed from '$old' to '$new'");
}
}
如果您使用 before_save
挂钩并且您有修改 assigned_user_id 字段的挂钩,请确保这些挂钩 运行 的顺序正确(挂钩数组中的第一个参数每个挂钩定义顺序)。