logic-hook

The Logic Hook framework allows us to execute custom code on system events such as when creating, editing, and deleting records. A logic hook is defined in a file as PHP function which execute when an event is triggered. For more detail about SuiteCRM logic hook, see here.

It is important to note that there are various ways to implement a logic hook, but only some logic hooks are triggered when using REST API.

Logic hook trigger with REST API

Teh following Logic Hooks are trigger from REST API call.

  • after_delete: Fired when a record is deleted.
  • after_relationship_add: Fired after a relationship is added between two records. Note that this may be called twice, once for each side of the relationship.
  • after_relationship_delete: Fired after a relationship between two records is deleted.
  • after_restore: Fired after a record is undeleted.
  • after_retrieve: Fired after a record is retrieved from the DB.
  • after_save: Fired after a record is saved. Note that due to some peculiarities some related modules may not be persisted to the database. The logic hook is fired within the SugarBean classes save method. Some implementing classes may save related beans after this method returns. A notable example of this is the saving of email addresses in Company modules.
  • before_delete: Fired before a record is deleted.
  • before_relationship_add: Fired before a relationship is added between two records. Note that this may be called twice, once for each side of the relationship.
  • before_relationship_delete: Fired before a relationship between two records is deleted. Note that this may be called twice, once for each side of the relationship.
  • before_restore: Fired before a record is undeleted.
  • before_save: Fired before a record is saved.
  • handle_exception: Fired when an exception occurs in a record.

Avoid process_record logic hook

process_record trigger when viewing record list from web portal. Typically you should avoid using that logic hook for any serious business logic.

Fixing the issue

If you find logic are not triggered, set logger level  to "debug" option, trigger REST API and examine sugarcrm.log file. Find warning and error in the log. Common issues are using depreciated API, which execute with portal but does not execute with REST API. In this case, deprecated depreciated usage case to newer format.

Another common issue is some filter function that check additional parameter are not appear when calling REST API.