Open js alert after_save hook

Hi, there,
I’m trying to do something relatively simple but complicated.
I would like to present a popup after saving a call.
I have registered a new logic_hooks in ‘/custom/modules/Calls/logic_hooks.php’

$hook_array['after_save'][] = Array(
                              1,
                              'openMeetingAfterCall',
                              'custom/modules/Calls/openMeetingAfterCall.php',
                              'EliAfterSaveCallLogicHook',
                              'openMeeting');

In the file ‘openMeetingAfterCall.php’ I have inserted this simple code to carry out an alert javascript

<?php
class EliAfterSaveCallLogicHook
     {
         function openMeeting($bean, $event, $arguments)
         {
           //var_dump($event);
           echo "<script type= \"text/javascript\">alert('Hello!')</script>"
           ;
         }
     }
?>

When I save a call, nothing happens.

Check your console, there must be JS error.

Try to create seperate echo like this.

function openMeeting($bean, $event, $arguments)
{
//var_dump($event);
echo “”;
}

as much your code is clean, you are good to debug and fix issue.

Hi ashish,
I set the code as suggested but still the alert is not executed… I reported the errors of the console in the attachment. Maybe the script conflicts with another one?

If I insert a ‘die()’ at the end of the script, the js alert works, of course then all the CRM code dies :wink:

<?php
class EliAfterSaveCallLogicHook
     {
         function openMeeting($bean, $event, $arguments)
         {
           echo "<script>";
            echo "alert('Hello!')";
            echo "</script>";
            die();
         }
     }
?>

This is because PHP is executing at Server side and it is not returned to client as execution is till going on.

When you put “die” , execution stops and it sent to client and that “alert” appear.

Now, you need to understand restrictions of client side and server side scripts.

So may be you do do code in some other way. Rather than using hooks.