SuiteCRM: redirect to editview using foresesave hook logic

Redirect to editview from beforesave hook logic

I am trying to redirect from it before caching logic persists if an error occurs in it. It should redirect to edit the error view. I am using this code:

function ShowError($errorMsg,$beanID){
    try{
        SugarApplication::appendErrorMessage('An error has been occured: '.$errorMsg);
        $params = array(
            'module'=> 'ad123_Ads',
            'action'=>'EditView', 
            'id' => $beanID
        );
        SugarApplication::redirect('index.php?' . http_build_query($params));
    } catch (Exception $e) {
        echo 'Caught exception: ',  $e, "\n";
    }

}

      

But the problem is that after the redirection, all fields become blank.

+3


source to share


3 answers


One of the parameters is incorrect, it should be record

instead id

.

Try the following:



try{
         SugarApplication::appendErrorMessage('An error has been occured: '.$errorMsg);
                $params = array(
                  'module'=> 'ad123_Ads',
                  'action'=>'EditView', 
                  'record' => $beanID
                );
        SugarApplication::redirect('index.php?' . http_build_query($params));
            }
    catch (Exception $e) {
          echo 'Caught exception: ',  $e, "\n";
        }

      

I do not recommend such checks, as you will lose the changes made to the form. Typically, a JS validation needs to be performed before submitting so that the user has time to fix bugs before submitting and lose all changes.

0


source


SugarApplication::appendErrorMessage('End Date must be after Start Date');
$queryParams = array(
                'module' => $module_name,
                'action' => $action,
                'record' => $recordId,
            );
            SugarApplication::redirect('index.php?' . http_build_query($queryParams));

      

Here $ module_name is the module you are writing the boolean hook to. $ action is "EditView" or "DetailView". $ recordId - $ bean → id



You need to understand that before the hook_shave logic, the post id will not be returned as it has not been assigned yet. This will return the page.

I think the best way to handle this is using hook_save logic. When you pass a bean -> id to the entry above, it will restore all the values ​​that are in the form.

0


source


I noticed that if you go to the verbose / editable view from the filtered list, SugarApplication :: redirect correctly brings you to the verbose view, but the filter and the 'next' and 'previous' arrow functions are rejected. I made a mistake?

0


source







All Articles