{"id":45122,"date":"2022-01-14T07:46:59","date_gmt":"2022-01-14T07:46:59","guid":{"rendered":"https:\/\/dev.outrightcrm.in\/dev\/store\/?p=45122"},"modified":"2023-12-18T11:50:17","modified_gmt":"2023-12-18T11:50:17","slug":"logic-hooks-in-suitecrm","status":"publish","type":"post","link":"https:\/\/dev.outrightcrm.in\/dev\/store\/blog\/logic-hooks-in-suitecrm\/","title":{"rendered":"Logic Hooks in SuiteCRM: How to Create it?"},"content":{"rendered":"\n<p>The Most significant thing to do is making a CRM software Personalized for certain events. Yes, Workflow is a decent option for handling and managing things effectively. But if a Developer gets into a complicated requirement then nothing can help them except \u201cLogic Hooks\u201d. Every event will be updated to your records like if you create and edit any Business record.&nbsp;<\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What is SuiteCRM Logic Hooks?<\/strong><\/h2>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>In very simple words, Logic Hooks allow a user to add actions to any event like a user can use this development strategy for creating, editing, and deleting any business record. It helps in executing the whole process when any event is triggered. An Event can be summarised as Save, delete, restore, retrieve, etc.&nbsp;<br><\/p>\n\n\n\n<p>Are you curious to know the Capabilities of this Development strategy?&nbsp;<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Helpful in Modifying each Business record before\/after it gets saved on Database.&nbsp;<\/li>\n\n\n\n<li>Logic Hooks can update other Database\/third party sources based on actions performed in your CRM.&nbsp;<\/li>\n\n\n\n<li>Sending of Email messages to any record.&nbsp;<\/li>\n<\/ol>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>How can you Create Logic Hooks in SuiteCRM?<\/strong><\/h3>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Add the below code in the following path: <code>custom\/modules\/Cases\/logic_hooks.php<\/code><\/p>\n\n\n\n<div class=\"hook_div\" style=\"background-color: #9e9e9e2e;font-size: 14px;line-height: 26px;padding: 5px 0px 5px 15px;border: 1px solid #80808029;!important\">\n$hook_array[&#8216;before_save&#8217;][]=Array(1,&#8217;assignUser&#8217;,&#8217;custom\/modules\/Cases\/Example.php&#8217;, &#8216;UpdateLogichookClass&#8217;, &#8216;updateLogichooksmethod&#8217;);\n<\/div>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong><em>Let us create a new file on Path custom\/modules\/Cases\/Example.php , open this file and put below content into that.<\/em><\/strong><\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-preformatted\"> &lt;?php\n\nClass UpdateLogichookClass&nbsp; {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;function updateLogichooksmethod( $bean, $event, $arguments)&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/Query ACCOUNTS table for assigned_user_id value of parent Account\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$case_id = $bean-&gt;id;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$acct_id = $bean-&gt;account_id;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$query =&nbsp; \"SELECT accts.assigned_user_id FROM accounts accts \";\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$query .= \"WHERE accts.id = '$acct_id' LIMIT 1\";\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$results = $bean-&gt;db-&gt;query($query, true);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$row = $bean-&gt;db-&gt;fetchByAssoc($results);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$user_id = $row['assigned_user_id'];\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/Change assigned_user_id value on Case\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$bean-&gt;assigned_user_id = $user_id;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}\n}\n?&gt;\n\n<\/pre>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading has-text-align-center\"><strong>All Three Contexts of Logic Hooks<\/strong><\/h2>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>The top Three context types you need to know: Applications Hooks, User Hooks, and Module Hooks.&nbsp;<br><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>User Level Hooks<\/strong><\/h3>\n\n\n\n<p>This context executes the logic for user action for <strong>Log-in<\/strong> and <strong>Log-out<\/strong> time.&nbsp;<br><\/p>\n\n\n\n<p><em><strong>Types of User Level Hooks are:<\/strong><\/em><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>after_login<\/li>\n\n\n\n<li>after_logout<\/li>\n\n\n\n<li>before_logout&nbsp;<\/li>\n\n\n\n<li>login_failed<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>We have a Great example of <a aria-label=\"SuiteCRM User Activity Tracker (opens in a new tab)\" href=\"https:\/\/dev.outrightcrm.in\/dev\/store\/product\/suitecrm-user-activity-tracker-lite\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>SuiteCRM User Activity Tracker<\/strong><\/a> Product here. If any user enters into the CRM software the hook will add action to the event. The whole team will get to know the log-in time of the user and Log-out time too. Even with the accurate time too.<\/li>\n<\/ul>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Module Level Hooks<\/strong><\/h3>\n\n\n\n<p>This context executes the logic for a specific Module of SuiteCRM software. It is located in <\/p>\n\n\n\n<pre><code>.\/custom\/Extension\/modules\/&lt;module&gt;\/Ext\/LogicHooks\/my_hook_1.php<br><\/code><\/pre>\n\n\n\n<p>Users are free to take any name of a file <code>(my_hook_1.php)<\/code> as this is part of the extension.<br><\/p>\n\n\n\n<p><strong><em>Types of Module Hooks are<\/em><\/strong><\/p>\n\n\n\n<ul><li style=\"color:#FF0000\">after_delete<\/li><\/ul>\n\n\n\n<p>Here we would like to share an Example of <a aria-label=\"SuiteCRM Recycle Bin (opens in a new tab)\" href=\"https:\/\/dev.outrightcrm.in\/dev\/store\/product\/suitecrm-recycle-bin\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>SuiteCRM Recycle Bin<\/strong><\/a> Product. A user deletes a Business record from a module of SuiteCRM. The After_delete logic hook easily gets executed when a record gets deleted. Hook will add the user action on that event.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>before_delete<\/li>\n<\/ul>\n\n\n\n<p>Let\u2019s understand this with an example of our unrivaled Plugin Google Calendar Integration with SuiteCRM. A user deleted a few client meeting details on SuiteCRM. So, before the delete process gets updated on the database of SuiteCRM, the action will execute first on Google Calendar platform.&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>after_relationship_delete<\/li>\n\n\n\n<li>after_relationship_Add<\/li>\n<\/ul>\n\n\n\n<p>To know this, let\u2019s take an example of Two modules of SuiteCRM: Lead and Account. You added the relationship between both these modules. Here the Logic Hooks will execute each side of the relationship. If you edit lead details in Account module or do changes of Account details in Lead module, the hook will run for both.&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>after_restore<\/li>\n<\/ul>\n\n\n\n<p> It executes after your records gets undeleted.  <\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>before_restore<\/li>\n<\/ul>\n\n\n\n<p> It executes before your records gets undeleted. <\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>After_save<\/li>\n<\/ul>\n\n\n\n<p>Here is an example of SuiteCRM Google Calendar Product. Suppose if you save any important Business meeting or event of your client in SuiteCRM, hook execute the action by saving directly on the Google Calendar in real-time. All team members get updates on the time.&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>before_save<\/li>\n<\/ul>\n\n\n\n<p><a href=\"https:\/\/dev.outrightcrm.in\/dev\/store\/product\/suitecrm-mailchimp-integration-premium\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"SuiteCRM Mailchimp Integration (Premium) (opens in a new tab)\">SuiteCRM Mailchimp Integration (Premium)<\/a> product is the best example here. If you update a subscriber&#8217;s list in SuiteCRM software than before it updates the database of SuiteCRM, Hook executes the action on Mailchimp first. This Before_save performs in the field of Edit View.&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>after_retrieve<\/li>\n<\/ul>\n\n\n\n<p>Let\u2019s understand this with the Extension of Twilio Click to call. Your call recordings are saved in your Database. Now you would like to see recordings in Detail View and in HTML Format. It retrieves all this from Database. All recordings will be visible in the Detail View.&nbsp;<\/p>\n\n\n\n<p><strong><em>This After_retrieve performs in the field of Edit view and Detail view.&nbsp;<\/em><\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>process_record<\/li>\n<\/ul>\n\n\n\n<p>For this, let us share an example of <a href=\"https:\/\/www.outrightcrm.com\/\" target=\"_blank\" rel=\"noopener\">SuiteCRM<\/a> Direct delete from Listview. A user performs an action to delete some unwanted records in the CRM. The Prcoess_record will see how many records are there in the field. After that, it adds the button on listview.\u00a0<\/p>\n\n\n\n<p><strong><em>This Process_record performs in the field of ListView, Sub-panel, Pop-up, and dashlet view<\/em><\/strong><\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Application Level Hooks<\/strong><\/h3>\n\n\n\n<p>The Third context executes the hooks when a user is working with the Global applications. This context is not recommended for the Modules or any Plugin. And it is located in <br><\/p><pre><code>.\/custom\/Extension\/Application\/EXT\/LogicHooks\/XYZ.PHP&gt;<\/code><\/pre>\n\n\n\n<p>Types of Application Hooks are<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>after_entry_point<\/li>\n\n\n\n<li>after_UI_Frame<\/li>\n\n\n\n<li>after_UI_Footer<\/li>\n\n\n\n<li>Server_round_trip: It executes when page loading ends and server successfully calculates loading time.&nbsp;<\/li>\n<\/ul>\n\n\n\n<p>For the Application Hooks, we have an example of <a rel=\"noreferrer noopener\" aria-label=\"Global Hide Manager (Premium) (opens in a new tab)\" href=\"https:\/\/dev.outrightcrm.in\/dev\/store\/product\/suitecrm-global-hide-manager-premium\/\" target=\"_blank\">Global Hide Manager (Premium)<\/a> Plugin. When a user adds an action for hiding Element Class or ID, hooks will see what Element to hide in CRM software. Hooks execute this action on the event and hide all these from the Loaded page.&nbsp;<\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>How will you know the changes in Previous and New Values?<\/strong><\/h3>\n\n\n\n<p>If it is necessary for your business team to know whether the change has occurred or not, use fetched_row.&nbsp;<br><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> if ($bean-&gt;fetched_row['{field}'] != $bean-&gt;{field})\n{\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/logic\n}\n\n <\/pre>\n\n\n\n<p><strong>Another Example:<\/strong><\/p>\n\n\n\n<p>Checking few values for a field \u201cstatus\u201d and send email to anyone<\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<pre class=\"wp-block-preformatted\"> if($bean-&gt;status == \u201cNew\u201d || $bean-&gt;status == \u201cIn Process\u201d)\n{\n&nbsp;&nbsp;&nbsp;&nbsp;\/\/Code for Sending Email to anyone\n}\n\n <\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The Most significant thing to do is making a CRM software Personalized for certain events. Yes, Workflow is a decent [&hellip;]<\/p>\n","protected":false},"author":3977,"featured_media":45212,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[57,112],"tags":[],"class_list":["post-45122","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-api","category-crm"],"acf":[],"_links":{"self":[{"href":"https:\/\/dev.outrightcrm.in\/dev\/store\/wp-json\/wp\/v2\/posts\/45122","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.outrightcrm.in\/dev\/store\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.outrightcrm.in\/dev\/store\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.outrightcrm.in\/dev\/store\/wp-json\/wp\/v2\/users\/3977"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.outrightcrm.in\/dev\/store\/wp-json\/wp\/v2\/comments?post=45122"}],"version-history":[{"count":0,"href":"https:\/\/dev.outrightcrm.in\/dev\/store\/wp-json\/wp\/v2\/posts\/45122\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dev.outrightcrm.in\/dev\/store\/wp-json\/wp\/v2\/media\/45212"}],"wp:attachment":[{"href":"https:\/\/dev.outrightcrm.in\/dev\/store\/wp-json\/wp\/v2\/media?parent=45122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.outrightcrm.in\/dev\/store\/wp-json\/wp\/v2\/categories?post=45122"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.outrightcrm.in\/dev\/store\/wp-json\/wp\/v2\/tags?post=45122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}