Redirect with a custom error message in SugarCRM

If your looking to redirect with a custom error message in Sugarcrm the following code snippet shows you how to do it. This could be used within a controller action for example if a certain condition is not met then redirect back to the module and display an error.

//Append error msg 
SugarApplication::appendErrorMessage('Action Prohibited: Cannot Create or Edit Products.');
        //set params
        $params = array(
            'module'=> 'RL_SalesHistory', //the module you want to redirect to
            'action'=>'DetailView', //the view within that module
            'record' => $_REQUEST['record'], //the record id
        );
//redirect       
SugarApplication::redirect('index.php?' . http_build_query($params))

Andy
About

Software Developer from Falkirk, Central Scotland.

Posted in SugarCRM development development hints and tips
One comment on “Redirect with a custom error message in SugarCRM
  1. Anum says:

    What if we want to redirect in sugar 6.5 without saving the updates?

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>