{"id":239,"date":"2019-10-08T17:37:36","date_gmt":"2019-10-08T17:37:36","guid":{"rendered":"https:\/\/www.techcrm.in\/blogs\/?p=239"},"modified":"2020-09-08T14:53:09","modified_gmt":"2020-09-08T09:23:09","slug":"populate-a-dropdown-list-from-the-database","status":"publish","type":"post","link":"https:\/\/www.techcrm.in\/blogs\/populate-a-dropdown-list-from-the-database\/","title":{"rendered":"Populate a Dropdown list from the database"},"content":{"rendered":"\n<p> It will be done by simple steps, <\/p>\n\n\n\n<p><strong>Step 1:<\/strong> What you need to do is to create a custom util function and then tell your vardefs for that field to call the custom util function.<\/p>\n\n\n\n<p><strong>Path:<\/strong>  custom\/Extension\/application\/Ext\/Utils\/&lt;any_name>.php add below your code as per requirement. For example,<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function getAccounts(){\n    static $accounts = null;\n    if(!$accounts){\n        global $db;\n        $query = \"SELECT id, name FROM accounts\";\n        $result = $db->query($query, false);\n\n        $accounts = array();\n        $accounts[''] = '';\n\n        while (($row = $db->fetchByAssoc($result)) != null) {\n            $accounts[$row['id']] = $row['name'];\n        }\n    }\n    return $accounts;\n}<\/code><\/pre>\n\n\n\n<p><strong>Step 2:<\/strong>  To extend vardefs we need to create a file. custom\/Extension\/modules\/&lt;desired_module>\/Ext\/Vardefs\/&lt;anyname>.php <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n$dictionary[\"&lt;MODULE_OBJECT_NAME>\"][\"fields\"][\"&lt;FIELD_NAME>\"][function\"]='getAccounts';<\/code><\/pre>\n\n\n\n<p><strong>Step 3:<\/strong>  Now go to\u00a0<strong>Admin > Repair > Quick Repair and Rebuild.<\/strong><\/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;desired_module> means the module name you see in the URL, for example, Contacts, Leads, etc.<\/em><br><em>Here, &lt;anyname> means the any file name\u00a0for example, custom_fields, search_fields, etc.<\/em><br><em>Here, &lt;MODULE_OBJECT_NAME> means module object\u00a0for example Account,Contact, etc.<\/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>It will be done by simple steps, Step 1: What you need to do is to create a custom util function and then tell your vardefs for that field to call the custom util function. Path: custom\/Extension\/application\/Ext\/Utils\/&lt;any_name>.php add below your code as per requirement. For example, Step 2: To extend vardefs we need to create [&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":[23,12,13],"class_list":["post-239","post","type-post","status-publish","format-standard","hentry","category-sugarcrm","category-suitecrm","tag-dropdown","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>Populate a Dropdown list from the database - 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\/populate-a-dropdown-list-from-the-database\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Populate a Dropdown list from the database - TechCRM\" \/>\n<meta property=\"og:description\" content=\"It will be done by simple steps, Step 1: What you need to do is to create a custom util function and then tell your vardefs for that field to call the custom util function. Path: custom\/Extension\/application\/Ext\/Utils\/&lt;any_name&gt;.php add below your code as per requirement. For example, Step 2: To extend vardefs we need to create [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.techcrm.in\/blogs\/populate-a-dropdown-list-from-the-database\/\" \/>\n<meta property=\"og:site_name\" content=\"TechCRM\" \/>\n<meta property=\"article:published_time\" content=\"2019-10-08T17:37:36+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-09-08T09:23:09+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\/populate-a-dropdown-list-from-the-database\/\",\"url\":\"https:\/\/www.techcrm.in\/blogs\/populate-a-dropdown-list-from-the-database\/\",\"name\":\"Populate a Dropdown list from the database - TechCRM\",\"isPartOf\":{\"@id\":\"https:\/\/www.techcrm.in\/blogs\/#website\"},\"datePublished\":\"2019-10-08T17:37:36+00:00\",\"dateModified\":\"2020-09-08T09:23:09+00:00\",\"author\":{\"@id\":\"https:\/\/www.techcrm.in\/blogs\/#\/schema\/person\/992dfe427bb53dcdfd72dd80e3ef9dbc\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.techcrm.in\/blogs\/populate-a-dropdown-list-from-the-database\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.techcrm.in\/blogs\/populate-a-dropdown-list-from-the-database\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.techcrm.in\/blogs\/populate-a-dropdown-list-from-the-database\/#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\":\"Populate a Dropdown list from the database\"}]},{\"@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":"Populate a Dropdown list from the database - 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\/populate-a-dropdown-list-from-the-database\/","og_locale":"en_US","og_type":"article","og_title":"Populate a Dropdown list from the database - TechCRM","og_description":"It will be done by simple steps, Step 1: What you need to do is to create a custom util function and then tell your vardefs for that field to call the custom util function. Path: custom\/Extension\/application\/Ext\/Utils\/&lt;any_name>.php add below your code as per requirement. For example, Step 2: To extend vardefs we need to create [&hellip;]","og_url":"https:\/\/www.techcrm.in\/blogs\/populate-a-dropdown-list-from-the-database\/","og_site_name":"TechCRM","article_published_time":"2019-10-08T17:37:36+00:00","article_modified_time":"2020-09-08T09:23:09+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\/populate-a-dropdown-list-from-the-database\/","url":"https:\/\/www.techcrm.in\/blogs\/populate-a-dropdown-list-from-the-database\/","name":"Populate a Dropdown list from the database - TechCRM","isPartOf":{"@id":"https:\/\/www.techcrm.in\/blogs\/#website"},"datePublished":"2019-10-08T17:37:36+00:00","dateModified":"2020-09-08T09:23:09+00:00","author":{"@id":"https:\/\/www.techcrm.in\/blogs\/#\/schema\/person\/992dfe427bb53dcdfd72dd80e3ef9dbc"},"breadcrumb":{"@id":"https:\/\/www.techcrm.in\/blogs\/populate-a-dropdown-list-from-the-database\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.techcrm.in\/blogs\/populate-a-dropdown-list-from-the-database\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.techcrm.in\/blogs\/populate-a-dropdown-list-from-the-database\/#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":"Populate a Dropdown list from the database"}]},{"@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\/239","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=239"}],"version-history":[{"count":1,"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/posts\/239\/revisions"}],"predecessor-version":[{"id":240,"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/posts\/239\/revisions\/240"}],"wp:attachment":[{"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/media?parent=239"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/categories?post=239"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/tags?post=239"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}