{"id":108,"date":"2019-08-24T16:23:04","date_gmt":"2019-08-24T16:23:04","guid":{"rendered":"https:\/\/www.techcrm.in\/blogs\/?p=108"},"modified":"2020-09-08T14:55:48","modified_gmt":"2020-09-08T09:25:48","slug":"filter-by-related-modules-field","status":"publish","type":"post","link":"https:\/\/www.techcrm.in\/blogs\/filter-by-related-modules-field\/","title":{"rendered":"Filter by related module&#8217;s field"},"content":{"rendered":"\n<p> At times we have clients asking for similar requirement, that they want to filter results by related module&#8217;s field. <\/p>\n\n\n\n<p>Lets take basic modules and achieve similar goal by coding. Here, one needs to have idea about creating basic MySQL query. <\/p>\n\n\n\n<p> We have Accounts and Contacts module in SugarCRM. Accounts has one-many relationship with Contacts. We will add Accounts module&#8217;s type field in Contacts search. <\/p>\n\n\n\n<p>Steps are as below,<\/p>\n\n\n\n<p><strong>Step 1 :<\/strong>  Create non-db field in Contacts module named as account_type_search. Write following code into custom\/Extensions\/modules\/Contacts\/Ext\/Vardefs\/&lt;anyname&gt;.php <\/p>\n\n\n\n<p><strong>Step 2 :<\/strong>  Write following code into search field definition. Copy modules\/Contacts\/metadata\/SearchFields.php to custom\/modules\/Contacts\/metadata\/SearchFields.php if doesn&#8217;t exist and write following code into it. If it exists at custom\/modules\/Contacts\/metadata\/SearchFields.php then add following code<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>'account_type_search' => array (\n\t'db_field' =>\n\tarray (\n\t  0 => 'id',\n\t),\n\t'query_type' => 'format',\n\t'operator' => 'subquery',\n\t'subquery' => 'SELECT accounts_contacts.contact_id FROM accounts_contacts\n\t\t\t\t   INNER JOIN accounts ON accounts.id = accounts_contacts.account_id AND accounts.deleted = 0\n\t\t\t\t   WHERE accounts_contacts.deleted = 0 AND accounts.account_type IN ({0})',\n),<\/code><\/pre>\n\n\n\n<p><strong>Step 3 :<\/strong>  Create custom\/modules\/Contacts\/metadata\/metafiles.php and write following code into it. If it exists at custom\/modules\/Contacts\/metadata\/metafiles.php, then do changes as per your needs.&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n$metafiles['Contacts']['searchfields']='custom\/modules\/Contacts\/metadata\/SearchFields.php';<\/code><\/pre>\n\n\n\n<p><strong>Step 4 :<\/strong> Add account_type_search field for searching into custom\/modules\/Contacts\/metadata\/searchdefs.php through studio. <\/p>\n\n\n\n<p><strong>Step 5 :<\/strong>  Do &#8220;Quick Repair And Rebuild&#8221; from admin. <\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>Note :<\/strong><\/p><cite> <em>Here, &lt;<\/em>anyname<em>&gt; means the any file name <\/em> <em>for example, custom_fields, search_fields, etc.<\/em> <em> .<\/em> <\/cite><\/blockquote>\n\n\n\n<p>Hope you find this blog post helpful.<\/p>\n\n\n\n<p>Feel free to add comments and queries, that helps us to improve the quality of posts.<\/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>At times we have clients asking for similar requirement, that they want to filter results by related module&#8217;s field. Lets take basic modules and achieve similar goal by coding. Here, one needs to have idea about creating basic MySQL query. We have Accounts and Contacts module in SugarCRM. Accounts has one-many relationship with Contacts. We [&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":[17,12,13],"class_list":["post-108","post","type-post","status-publish","format-standard","hentry","category-sugarcrm","category-suitecrm","tag-filter","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>Filter by related module&#039;s field - 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\/filter-by-related-modules-field\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Filter by related module&#039;s field - TechCRM\" \/>\n<meta property=\"og:description\" content=\"At times we have clients asking for similar requirement, that they want to filter results by related module&#8217;s field. Lets take basic modules and achieve similar goal by coding. Here, one needs to have idea about creating basic MySQL query. We have Accounts and Contacts module in SugarCRM. Accounts has one-many relationship with Contacts. We [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.techcrm.in\/blogs\/filter-by-related-modules-field\/\" \/>\n<meta property=\"og:site_name\" content=\"TechCRM\" \/>\n<meta property=\"article:published_time\" content=\"2019-08-24T16:23:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-09-08T09:25:48+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=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.techcrm.in\/blogs\/filter-by-related-modules-field\/\",\"url\":\"https:\/\/www.techcrm.in\/blogs\/filter-by-related-modules-field\/\",\"name\":\"Filter by related module's field - TechCRM\",\"isPartOf\":{\"@id\":\"https:\/\/www.techcrm.in\/blogs\/#website\"},\"datePublished\":\"2019-08-24T16:23:04+00:00\",\"dateModified\":\"2020-09-08T09:25:48+00:00\",\"author\":{\"@id\":\"https:\/\/www.techcrm.in\/blogs\/#\/schema\/person\/992dfe427bb53dcdfd72dd80e3ef9dbc\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.techcrm.in\/blogs\/filter-by-related-modules-field\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.techcrm.in\/blogs\/filter-by-related-modules-field\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.techcrm.in\/blogs\/filter-by-related-modules-field\/#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\":\"Filter by related module&#8217;s field\"}]},{\"@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":"Filter by related module's field - 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\/filter-by-related-modules-field\/","og_locale":"en_US","og_type":"article","og_title":"Filter by related module's field - TechCRM","og_description":"At times we have clients asking for similar requirement, that they want to filter results by related module&#8217;s field. Lets take basic modules and achieve similar goal by coding. Here, one needs to have idea about creating basic MySQL query. We have Accounts and Contacts module in SugarCRM. Accounts has one-many relationship with Contacts. We [&hellip;]","og_url":"https:\/\/www.techcrm.in\/blogs\/filter-by-related-modules-field\/","og_site_name":"TechCRM","article_published_time":"2019-08-24T16:23:04+00:00","article_modified_time":"2020-09-08T09:25:48+00:00","author":"Navin Rakhonde","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Navin Rakhonde","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.techcrm.in\/blogs\/filter-by-related-modules-field\/","url":"https:\/\/www.techcrm.in\/blogs\/filter-by-related-modules-field\/","name":"Filter by related module's field - TechCRM","isPartOf":{"@id":"https:\/\/www.techcrm.in\/blogs\/#website"},"datePublished":"2019-08-24T16:23:04+00:00","dateModified":"2020-09-08T09:25:48+00:00","author":{"@id":"https:\/\/www.techcrm.in\/blogs\/#\/schema\/person\/992dfe427bb53dcdfd72dd80e3ef9dbc"},"breadcrumb":{"@id":"https:\/\/www.techcrm.in\/blogs\/filter-by-related-modules-field\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.techcrm.in\/blogs\/filter-by-related-modules-field\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.techcrm.in\/blogs\/filter-by-related-modules-field\/#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":"Filter by related module&#8217;s field"}]},{"@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\/108","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=108"}],"version-history":[{"count":2,"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/posts\/108\/revisions"}],"predecessor-version":[{"id":110,"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/posts\/108\/revisions\/110"}],"wp:attachment":[{"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/media?parent=108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/categories?post=108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/tags?post=108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}