如何在aftersave hooks logic-SuiteCRM中找到记录id

时间:2017-06-22 05:08:43

标签: php sugarcrm suitecrm

我在aftersave hooks逻辑中做了一些API调用。我需要从DB获取保存记录的Id,以便在钩子类中发生任何错误时将用户重定向到编辑视图。 这是我的错误代码重定向用户,但我需要记录ID:

function ShowError($errorMsg,$beanID){
    try{
        self::$already_ran = false;
        SugarApplication::appendErrorMessage($errorMsg);
            $params = array(
              'module'=> 'ad123_Ads',
              'return_module'=> 'ad123_Ads',
              'action'=>'EditView', 
              'record' => $beanID
            );
        SugarApplication::redirect('index.php?' . http_build_query($params));
    }
    catch (Exception $e) {
      echo 'Caught exception: ',  $e, "\n";
    }
}

1 个答案:

答案 0 :(得分:4)

钩子的第一个参数是钩子正在运行的bean,在aftersave钩子中你可以简单地从bean中获取id:

function myLogicHook(SugarBean $bean, $event, $arguments){
    echo "Bean id is ".$bean->id;
}