I know, this topic has been discussed here a few times. I also googled it and came always to the same result:
Unfortunately, this is not working for SuiteCRM 8x anymore. I tried it. I went also through the documentation and was thinking about a backend handler. But I don’t need to calcuated on the fly the content of the dropdown.
What I did so far:
I create getOutboundMails.php in custom\Extension\application\Ext\Utils:
<?php
$db = DBManagerFactory::getInstance();
function getOutboundMails() {
static $OutboundMails = null;
if(!$OutboundMails){
$query = 'SELECT id, name FROM outbound_email WHERE deleted=0';
$result = $db->query($query);
$OutboundMails = array();
$OutboundMails[''] = '';
while (($row = $db->fetchByAssoc($result)) != null) {
$OutboundMails[$row['id']] = $row['name'];
}
}
return $OutboundMails;
}
Then I created a custom varchar field in custom\Extension\modules\FP_events\Ext\Vardefs:
I crashed SuiteCRM. I found somehow the following error message :
PHP Fatal error: Uncaught Error: Class "DBManagerFactory" not found in /webroot/www/suitecrm_dev/public/legacy/custom/application/Ext/Utils/custom_utils.ext.php:6
Stack trace:
#0 /webroot/www/suitecrm_dev/public/legacy/include/utils.php(5702): include_once()
#1 /webroot/www/suitecrm_dev/public/legacy/include/entryPoint.php(109): require_once('/webroot/...')
#2 /webroot/www/suitecrm_dev/config/bootstrap.php(70): require_once('/webroot/...')
#3 /webroot/www/suitecrm_dev/bin/console(30): require('/webroot/...')
#4 {main}
thrown in /webroot/www/suitecrm_dev/public/legacy/custom/application/Ext/Utils/custom_utils.ext.php on line 6
After resetting it to the default code, the system was working again:
<?php
// $db = DBManagerFactory::getInstance();
function getOutboundMails() {
global $db;
static $OutboundMails = null;
if(!$OutboundMails){
$query = 'SELECT id, name FROM outbound_email WHERE deleted=0';
$result = $db->query($query);
$OutboundMails = array();
$OutboundMails[''] = '';
while (($row = $db->fetchByAssoc($result)) != null) {
$OutboundMails[$row['id']] = $row['name'];
}
}
return $OutboundMails;
}
the issue was, the field type was a textfield and not a selection field (dropdown). After updateing it in the db (changeing it to varchar(100) in the module_table_cstm as well as changeing it in the fields_meta_data) and gave it a default selection list, it works like a charm.