Prevent logic hook from being triggered

Hi,

I created an after_retrieve logic hook in Accounts.
It’s purpose is to call a web service and based on the result create new contacts for the account that is being viewed.

This works perfectly fine when opening an account. However, the hook is also triggered when opening or deleting a contact in the Contacts module. This happens because every contact is associated with an account which results in the after_retrieve hook to be executed again.

Is it possible to prevent the hook from being triggered when performing any other actions than just opening an account?

Within your function in your logic hook class you can use the $_REQUEST parameters to determine where the system is establishing this logic hook.

For example you can use the following:


if(isset($_REQUEST['module']) && $_REQUEST['module'] == 'Accounts'){
            // Code executed if the module is only Accounts
}

If you only want this to happen only on DetailView I would put in a further restriction that action = ‘DetailView’ like below:


if((isset($_REQUEST['module']) && $_REQUEST['module'] == 'Accounts') && ((isset($_REQUEST['action']) && $_REQUEST['action'] == 'DetailView'))){
            // Code executed if the module is only Accounts and in DetailView
}

Just a point here, you may need to set up a flag with you solution so that a contact doesn’t get created if there is one of the similar nature already exists. The after_retrieve hook does execute often. In the above example, it will run when you enter the record’s DetailView, but also when you save the record because the default response for the system to THEN go into the DetailView of the record therefore triggering the logic_hook. Hope that makes sense.

Hope this helps.

1 Like

Great, that’s exactly what I was looking for. Thanks!