Popup alert does not display when triggered by logic hook

Hello everyone,

I'm trying to do a simple thing in sugar : check if the assigned user already have a meeting when saving a new one on the same date/hours.

So, i've got a before_save logic hook which check if the assigned user already have meetings. It works well.

Now, i want to throw an alert to the user, it seems that the Confirm one is good : if confirmed, save the meeting. If cancelled, then go back to it and change the date.

I wrote this inside my logic hook, if the user is not available, then $isavailable is false.

if ($isavailable == false) { // User already has a meeting at this time => error    
 echo "<script type='text/javascript'>
 app.alert.show('message-id', {
level: 'confirmation',
messages: 'Confirm?',
autoClose: false,
onConfirm: function(){
alert('Confirmed!');
},
onCancel: function(){
alert('Cancelled!');
}
});</script>";

}
                                                                  
But the alert does not show.
And how can i make the cancel => go back to the current meeting. and the confirm => save the current meeting??

Can you please help me on that?

Thanks.
Gaëlle
Parents
  • Problem SOLVED!
    So, for those who were wondering : Jeff is totally right, and well, it's good to know : You can't return Javascript to the browser by logic hook (using eg
    echo "<script>alert('ETC');</script>" ;
    won't work).

    But i've achieved a way to do this : include a js file to your view, trigger an event (like a click), do an ajax call to a php file (personnally, i pass by an entryPoint) which has the sql queries/function for you. echo your datas and then manage the datas back in the ajax, like if success : alert(data);


  • Here is a way I found from joining other's comment and Published data.

    Add a bean factory for User to Logichook

    $user = BeanFactory::getBean('Users', $current_user->id);

    Add Function:

        function NotifyOnError($focus,$message, $usr ){
            throw new SugarApiExceptionInvalidParameter($message);
            $notifyBean = BeanFactory::getBean('Notifications');
            $notifyBean->assigned_user_id = $usr;
            $notifyBean->severity = 'warning'; // Check notifications_severity_list for available option
            $notifyBean->parent_type = $focus->opportunities;
            $notifyBean->parent_id = $focus->id;
            $notifyBean->created_by = $GLOBALS['current_user']->id;
            $notifyBean->name = translate('LBL_KEEP_ATTENTION', $focus->module_name);
            $notifyBean->save();
            return true;
        }

    Add Call to Error control

    $rtnerr = $this->NotifyOnError($this, 'OOPS - Something Bad Happened - Have an Admin check the log', $user->id);


    Bill Lefkoski

Reply
  • Here is a way I found from joining other's comment and Published data.

    Add a bean factory for User to Logichook

    $user = BeanFactory::getBean('Users', $current_user->id);

    Add Function:

        function NotifyOnError($focus,$message, $usr ){
            throw new SugarApiExceptionInvalidParameter($message);
            $notifyBean = BeanFactory::getBean('Notifications');
            $notifyBean->assigned_user_id = $usr;
            $notifyBean->severity = 'warning'; // Check notifications_severity_list for available option
            $notifyBean->parent_type = $focus->opportunities;
            $notifyBean->parent_id = $focus->id;
            $notifyBean->created_by = $GLOBALS['current_user']->id;
            $notifyBean->name = translate('LBL_KEEP_ATTENTION', $focus->module_name);
            $notifyBean->save();
            return true;
        }

    Add Call to Error control

    $rtnerr = $this->NotifyOnError($this, 'OOPS - Something Bad Happened - Have an Admin check the log', $user->id);


    Bill Lefkoski

Children
No Data