Loogic Hook on Calendar Module?

Hi!

I’m trying to create a logic_hook on my Calendar Module on Suitecrm7.9.7 when to appear the emergent window to create the event and I save it, but I made the logic of classic form but is not working :frowning:

literally, this is my code:

custom/modules/Calendar/logic_hooks.php

<?php $hook_version = 1; $hook_array = Array(); $hook_array["after_save"] = Array(); $hook_array["after_save"][] = Array( //Processing index. For sorting the array. 1, //Label. A string value to identify the hook. 'after_save example', //The PHP file where your class is located. 'custom/modules/Calendar/after_save_class.php', //The class the method is in. 'after_save_class', //The method to call. 'after_save_method' ); ?>

then : custom/modules/Calendar/after_save_class.php

<?php if (!defined("sugarEntry") || !sugarEntry) die("Not A Valid Entry Point"); class after_save_class { function after_save_method($bean, $event, $arguments) { echo ""; } } ?>

how can i to do it?? some idea?..

It looks correct…

To make sure it’s firing, I suggest you better use some PHP directly, for example logging a FATAL error in suitecrm.log.

This is better than outputting the Javascript with the alert, because it’s simpler. That way first you determine if the hook is firing, then move on to getting the Javascsipt onto the page.

Hi @pgr!

I understood, and I add a line to write into the log file like this:

<?php if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); class after_save_class { function after_save_method($bean, $event, $arguments) { $GLOBALS["log"]->fatal("*******"); echo ""; } } ?>

but when I delete the record, I go to see the suitecrm.log file but I can’t find the asterisks, and I tried this in other module and works fine… :S

Hhmm I don’t know… maybe there is something peculiar to the Calendar module…

Maybe you can try this neat trick to really see what SuiteCRM is trying to load, where it is looking for files:

https://pgorod.github.io/Audit-File-Accesses/

Also, if you increase your log level to DEBUG you will see some messages in the logs about hooks firing. Maybe that will give you ideas about where to put your code.

thanks @pgr !

You know? I was reviewing the process and I saw the log called suitecrm_1.log and the Message is written (the asterisks) $GLOBALS[“log”]->fatal("*******");

that minds that are working… the question is, why not is executing my javascript code echo "";

??..maybe could be 'cause is very fast the process? :S u.u

even i tried to redirect with php but… without success…

	    $GLOBALS['log']->fatal("*******");
		$GLOBALS['log']->fatal("Event Fired : LOGIC HOOK DESDE ==> /custom/modules/{module}/logic_hooks_class.php ******* $event {$bean->id} ".date('Y-m-d H:i:s'));
		header('Location: /index.php?module=Contacts&action=DetailView&record='.$bean->id.'&param_id=isnull');

Ok, so the hook is firing.

I don’t think you can just start trying to inject HTML or Javascript from a hook, they’re not meant for that. You should be overriding a view for that kind of thing…

But do you really need that Javascript? What exactly do you want the hook to do?

You right!

exactly, what I need is, when one record is deleted from Meetings module, I need that appears a popup, just that, that popup shows the google’s screen for agree some user to delete the event from google calendar and agree to the access,
do you understand?

in fact, my code is this:

that code is working fine but, the idea is that it should be fired after delete or remove relationship of an event record…

how you see??

Hooks can be called from other places that don’t even have a UI. For example, when you manipulate beans from a Scheduler, or from the API.

So a hook is not a good place to try and play with the UI. Try finding out which view object you can override, and intercept the action sooner (for example, when the button is clicked), not when the record is saved.

A different approach (I don’t know if it could work) would be to try and send that link to the Notification balloon on the top menu. I don’t know how to do it but I think you could find some posts here on the forums with code samples for that. This way, you could do it from the hook, writing the notification in the database, and the UI would show it on the next screen refresh.