3

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";
    }
}
Komal12
  • 3,340
  • 4
  • 16
  • 25
Kamran Ahmed
  • 179
  • 1
  • 2
  • 10

1 Answers1

4

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;
}
Jim
  • 22,354
  • 6
  • 52
  • 80