Logic Hook for Popup Message

Hi,
I’m trying to create an after_retrieve logic hook to show a popup message in detail view when my custom field candidate_no contains particular string values.
I keep getting syntax errors when trying to create the logic hook.

The code is as follows

<?php
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
   
    class popup_warning_class
    {
        function popup_warning_method($bean, $event, $arguments)
        {
           
             $candidate_no = $_REQUEST['candidate_no'];
			 if $candidate_no = 1234;
			 
			 die('testing');
           

        }
    }
?>

That’s basic PHP syntax, the IF requires parenthesis around the expression.


if ($candidate_no == 1234) {
    die('Testing');        
}

Then I also added brackets for the code to be executed when the expression is true. Not strictly necessary if you’re executing just one command, but good practice.

You also need a double == for comparison, otherwise you’re attributing (changing the variable on the left, not testing it). This can be a really confusing bug, pay attention to it.

1 Like

Thanks for the info pgr.

i had a similar question which i posted here https://suitecrm.com/suitecrm/forum/suitecrm-7-0-discussion/17807-display-allert-exeption-before-save#60076 - my solution:


         SugarApplication::appendErrorMessage('record cannot be saved !!!'.$errorMsg);
                $params = array(
                  'module'=> 'Accounts',
                  'action'=>'DetailView', 
                   'record' => $bean->id
                );
        SugarApplication::redirect('index.php?' . http_build_query($params).'&return_module=Accounts&return_action=DetailView&offset=1');

it will work if you use action->edit->save. if you use a inline edit, it will mess up the browser. I switched them off in Admin->System settings.

1 Like