{"id":128,"date":"2019-08-25T07:28:02","date_gmt":"2019-08-25T07:28:02","guid":{"rendered":"https:\/\/www.techcrm.in\/blogs\/?p=128"},"modified":"2020-09-08T14:55:47","modified_gmt":"2020-09-08T09:25:47","slug":"audit-relate-fields","status":"publish","type":"post","link":"https:\/\/www.techcrm.in\/blogs\/audit-relate-fields\/","title":{"rendered":"Audit relate fields"},"content":{"rendered":"\n<p>Plenty of times the forums have hit the same question, since I know SugarCRM.<\/p>\n\n\n\n<p>&#8220;How to audit relate fields?&#8221; No out of box solution for it!<\/p>\n\n\n\n<p>But I simply love the power of logic hooks.<\/p>\n\n\n\n<p>Lets win the world!<\/p>\n\n\n\n<p>For this blog post, we will audit Account name field under Contacts module.\n\n<\/p>\n\n\n\n<p>Steps are as below,<\/p>\n\n\n\n<p><strong>Step 1<\/strong>: Create a before save definition logic hook under custom\/modules\/Contacts\/logic_hooks.php <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n$hook_array['before_save'][] = Array(90, 'Audit account name', 'custom\/modules\/Contacts\/auditAcc.php','auditAccC', 'auditAccF');<\/code><\/pre>\n\n\n\n<p><strong>Step 2<\/strong>: Create file auditAcc.php under custom\/modules\/Contacts folder and add following code. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\nclass auditAccC{\n    function auditAccF($bean){\n        \/\/ check for the change\n        if($bean->fetched_rel_row['account_id'] != $bean->account_id){\n            \/\/ prepare an array to audit the changes in parent module's audit table\n            $aChange = array();\n            $aChange['field_name'] = 'account_id';\n            $aChange['data_type'] = 'relate';\n            $aChange['before'] = $bean->fetched_rel_row['account_id'];\n            $aChange['after'] = $bean->account_id;\n            \/\/ save audit entry\n            $bean->db->save_audit_records($bean, $aChange);\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p>\n\nBlink of an eye! Done! Test it out!<\/p>\n\n\n\n<p>Hope this helps and feels like missing piece is just found!<\/p>\n\n\n\n<p>Feel free to drop your comments.<\/p>\n\n\n\n<p>Your valuable feedback means a lot. <\/p>\n\n\n\n<p>You can contact us at&nbsp;<a rel=\"noreferrer noopener\" href=\"mailto:contact@urdhva-tech.com\" target=\"_blank\">info@techcrm.in<\/a><\/p>\n\n\n\n<p>Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Plenty of times the forums have hit the same question, since I know SugarCRM. &#8220;How to audit relate fields?&#8221; No out of box solution for it! But I simply love the power of logic hooks. Lets win the world! For this blog post, we will audit Account name field under Contacts module. Steps are as [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,9],"tags":[25,20,12,13],"class_list":["post-128","post","type-post","status-publish","format-standard","hentry","category-sugarcrm","category-suitecrm","tag-audit","tag-relate-field","tag-sugarcrm","tag-suitecrm"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Audit relate fields - TechCRM<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.techcrm.in\/blogs\/audit-relate-fields\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Audit relate fields - TechCRM\" \/>\n<meta property=\"og:description\" content=\"Plenty of times the forums have hit the same question, since I know SugarCRM. &#8220;How to audit relate fields?&#8221; No out of box solution for it! But I simply love the power of logic hooks. Lets win the world! For this blog post, we will audit Account name field under Contacts module. Steps are as [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.techcrm.in\/blogs\/audit-relate-fields\/\" \/>\n<meta property=\"og:site_name\" content=\"TechCRM\" \/>\n<meta property=\"article:published_time\" content=\"2019-08-25T07:28:02+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-09-08T09:25:47+00:00\" \/>\n<meta name=\"author\" content=\"Navin Rakhonde\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Navin Rakhonde\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.techcrm.in\/blogs\/audit-relate-fields\/\",\"url\":\"https:\/\/www.techcrm.in\/blogs\/audit-relate-fields\/\",\"name\":\"Audit relate fields - TechCRM\",\"isPartOf\":{\"@id\":\"https:\/\/www.techcrm.in\/blogs\/#website\"},\"datePublished\":\"2019-08-25T07:28:02+00:00\",\"dateModified\":\"2020-09-08T09:25:47+00:00\",\"author\":{\"@id\":\"https:\/\/www.techcrm.in\/blogs\/#\/schema\/person\/992dfe427bb53dcdfd72dd80e3ef9dbc\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.techcrm.in\/blogs\/audit-relate-fields\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.techcrm.in\/blogs\/audit-relate-fields\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.techcrm.in\/blogs\/audit-relate-fields\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.techcrm.in\/blogs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SugarCRM\",\"item\":\"https:\/\/www.techcrm.in\/blogs\/category\/sugarcrm\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Audit relate fields\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.techcrm.in\/blogs\/#website\",\"url\":\"https:\/\/www.techcrm.in\/blogs\/\",\"name\":\"TechCRM\",\"description\":\"Blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.techcrm.in\/blogs\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.techcrm.in\/blogs\/#\/schema\/person\/992dfe427bb53dcdfd72dd80e3ef9dbc\",\"name\":\"Navin Rakhonde\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.techcrm.in\/blogs\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/9cc8fd1b948255055b85e5d41dabfc6e704f806d180a1e21cb8fb378e2f5c022?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/9cc8fd1b948255055b85e5d41dabfc6e704f806d180a1e21cb8fb378e2f5c022?s=96&d=mm&r=g\",\"caption\":\"Navin Rakhonde\"},\"sameAs\":[\"https:\/\/www.techcrm.in\/\"],\"url\":\"https:\/\/www.techcrm.in\/blogs\/author\/navin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Audit relate fields - TechCRM","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.techcrm.in\/blogs\/audit-relate-fields\/","og_locale":"en_US","og_type":"article","og_title":"Audit relate fields - TechCRM","og_description":"Plenty of times the forums have hit the same question, since I know SugarCRM. &#8220;How to audit relate fields?&#8221; No out of box solution for it! But I simply love the power of logic hooks. Lets win the world! For this blog post, we will audit Account name field under Contacts module. Steps are as [&hellip;]","og_url":"https:\/\/www.techcrm.in\/blogs\/audit-relate-fields\/","og_site_name":"TechCRM","article_published_time":"2019-08-25T07:28:02+00:00","article_modified_time":"2020-09-08T09:25:47+00:00","author":"Navin Rakhonde","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Navin Rakhonde","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.techcrm.in\/blogs\/audit-relate-fields\/","url":"https:\/\/www.techcrm.in\/blogs\/audit-relate-fields\/","name":"Audit relate fields - TechCRM","isPartOf":{"@id":"https:\/\/www.techcrm.in\/blogs\/#website"},"datePublished":"2019-08-25T07:28:02+00:00","dateModified":"2020-09-08T09:25:47+00:00","author":{"@id":"https:\/\/www.techcrm.in\/blogs\/#\/schema\/person\/992dfe427bb53dcdfd72dd80e3ef9dbc"},"breadcrumb":{"@id":"https:\/\/www.techcrm.in\/blogs\/audit-relate-fields\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.techcrm.in\/blogs\/audit-relate-fields\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.techcrm.in\/blogs\/audit-relate-fields\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.techcrm.in\/blogs\/"},{"@type":"ListItem","position":2,"name":"SugarCRM","item":"https:\/\/www.techcrm.in\/blogs\/category\/sugarcrm\/"},{"@type":"ListItem","position":3,"name":"Audit relate fields"}]},{"@type":"WebSite","@id":"https:\/\/www.techcrm.in\/blogs\/#website","url":"https:\/\/www.techcrm.in\/blogs\/","name":"TechCRM","description":"Blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.techcrm.in\/blogs\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.techcrm.in\/blogs\/#\/schema\/person\/992dfe427bb53dcdfd72dd80e3ef9dbc","name":"Navin Rakhonde","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.techcrm.in\/blogs\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/9cc8fd1b948255055b85e5d41dabfc6e704f806d180a1e21cb8fb378e2f5c022?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9cc8fd1b948255055b85e5d41dabfc6e704f806d180a1e21cb8fb378e2f5c022?s=96&d=mm&r=g","caption":"Navin Rakhonde"},"sameAs":["https:\/\/www.techcrm.in\/"],"url":"https:\/\/www.techcrm.in\/blogs\/author\/navin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/posts\/128","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/comments?post=128"}],"version-history":[{"count":1,"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/posts\/128\/revisions"}],"predecessor-version":[{"id":129,"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/posts\/128\/revisions\/129"}],"wp:attachment":[{"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/media?parent=128"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/categories?post=128"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/tags?post=128"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}