Search code examples
phpmysqlsugarcrm

Troubleshooting dynamic dropdowns in SugarCRM 6.5


I had asked a question here a while back about setting up database populated dropdowns for SugarCRM. I received a really good answer and, after more php studies and a dev instance running, I decided to give it a shot. The instructions I followed can be found here. After I run the repair and rebuild, I would expect to see the custom field in my Fields list under the module in studio, but have not been able to find it. The module is named Makers (a1_makers as a database table). For good orders sake, there were no errors when I repaired/rebuilt after saving the files.

Per the instructions, I first created a php file with a custom function to query the database (custom/Extension/application/Ext/Utils/getMakers.php):

<?php
    function getMakers() {
    static $makers = null;
    if (!$makers){
            global $db;
            $query = "SELECT id, name FROM a1_maker";
            $result = $db->query($query, false);

            $accounts = array();
            $accounts[''] = '';

            while (($row = $db->fetchByAssoc($result)) !=null) {
                    $accounts[$row['id']] = $row['name'];
            }
    }
    return $makers;
 }
?>

Then, I set 'function' field in Vardefs to point to the function (custom/Extension/modules/Maker/Ext/Vardefs/makers_template.php):

<?php
     $dictionary['Maker']['fields']['list_of_makers'] = array (
          'name' => 'list_of_makers',
          'vname' => 'LBL_MKRLST'
          'function' => 'getMakers',
          'type' => 'enum',
          'len' => '100',
          'comment' => 'List of makers populated from the database',
    );
   ?>

Unfortunately, there are no errors and the repair/rebuild runs fine. I am just unable to see the custom field when I go into studio. Can anyone please help point out what I may be doing wrong?


Solution

  • I would recommend checking existence of newly created field 'list_of_makers' in cache/modules/Maker/Makervardefs.php file. If new field definition exists in that file, try add 'studio' => 'visible' to custom/Extension/modules/Maker/Ext/Vardefs/makers_template.php to get something like this:

    <?php
         $dictionary['Maker']['fields']['list_of_makers'] = array (
              'name' => 'list_of_makers',
              'vname' => 'LBL_MKRLST'
              'function' => 'getMakers',
              'type' => 'enum',
              'studio' => 'visible'
              'len' => '100',
              'comment' => 'List of makers populated from the database',
        );
    

    Try to edit your custom/modules/Maker/metadata/editviewdefs.php manually and insert field definition by hand in proper place if everything above won't work.