Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find record id in aftersave hooks logic-SuiteCRM

I am doing some API calls in aftersave hooks logic.One thing i need to get the Id of saved record from DB to redirect user to edit view if any error occurs in hooks class. This my error code to redirect user but i need the record 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";
    }
}
like image 349
Kamran Ahmed Avatar asked Nov 25 '25 07:11

Kamran Ahmed


1 Answers

The first argument for a hook is the bean that the hook is being run on, in an aftersave hook you can simply grab the id from the bean:

function myLogicHook(SugarBean $bean, $event, $arguments){
    echo "Bean id is ".$bean->id;
}
like image 56
Jim Avatar answered Nov 26 '25 20:11

Jim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!