Show/hide dropdown values in SuiteCRM 8.9
04:15 14 Nov 2025

I am using SuiteCRM 8.9, and I am trying to show/hide dropdown values using logic hooks. But it is not working.

/var/www/suitecrm/public/legacy/custom/modules/MPC_Job_Requirements/ExtFilterDropdownHook.php

fatal('=== DROPDOWN FILTER HOOK TRIGGERED ===');
        $GLOBALS['log']->fatal('Module: ' . $bean->module_name);

        global $current_user, $app_list_strings;
        
        // Get user's security groups
        require_once('modules/SecurityGroups/SecurityGroup.php');
        $securityGroups = SecurityGroup::getUserSecurityGroups($current_user->id);
        $groupNames = array_column($securityGroups, 'name');

    // DEBUG: Log security groups
        $GLOBALS['log']->fatal('User: ' . $current_user->user_name);
        $GLOBALS['log']->fatal('User Groups: ' . print_r($groupNames, true));
        
        // === CONFIGURATION: Define your dropdown field filters here ===
        $dropdownConfigs = [
            'status' => [  // Replace 'status' with your actual field name
                'Sales' => ['draft', 'sales_review'],  // Replace with actual group names and values
                'Finance' => ['finance_review'],
            ],
            // Add more fields as needed:
            // 'your_field_name_c' => [
            //     'GroupName' => ['value1', 'value2'],
            // ],
        ];
        
        // Process each configured dropdown field
        foreach ($dropdownConfigs as $fieldName => $groupConfig) {
            $this->filterField($bean, $fieldName, $groupNames, $groupConfig);
        }
    }
    
    private function filterField($bean, $fieldName, $userGroups, $groupConfig)
    {
        global $app_list_strings;
        
        // Check if field exists in bean definition
        if (!isset($bean->field_defs[$fieldName])) {
            return;
        }
        
        // Get the dropdown list name
        $dropdownListName = $bean->field_defs[$fieldName]['options'] ?? null;
        
        if (!$dropdownListName || !isset($app_list_strings[$dropdownListName])) {
            return;
        }
        
        $fullDropdownList = $app_list_strings[$dropdownListName];
        
        // Collect allowed values based on user's security groups
        $allowedKeys = [];
        foreach ($userGroups as $groupName) {
            if (isset($groupConfig[$groupName])) {
                $allowedKeys = array_merge($allowedKeys, $groupConfig[$groupName]);
            }
        }
        
        // Remove duplicates
        $allowedKeys = array_unique($allowedKeys);
        
        // Apply filter if restrictions exist
        if (!empty($allowedKeys)) {
            $filteredList = array_intersect_key(
                $fullDropdownList,
                array_flip($allowedKeys)
            );
            
            // Override the dropdown list for this request
            $app_list_strings[$dropdownListName] = $filteredList;
        }
    }
}

/var/www/suitecrm/public/legacy/custom/modules/MPC_Job_Requirements/Extlogic_hooks.php

php crm suitecrm