0

I am using SuiteCRM 8.9, and I am trying to show/hide dropdown values using logic hooks. But it is not working. The hook is not running. Users under the Sales security group should only see draft and sales_review in their status dropdown. Similarly, users under Finance security group should see only finance_review in the dropdown.

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

<?php
if (!defined('sugarEntry') || !sugarEntry) {
 die('Not A Valid Entry Point');
}
class FilterDropdownHook
{
 public function filterDropdownValues($bean, $event, $arguments)
 {
 // DEBUG: Write to log file
 $GLOBALS['log']->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
// Do not store anything in this file that is not part of the array or the hook version.
// This file will be automatically rebuilt in the future.
$hook_version = 1;
$hook_array = Array();
$hook_array['after_retrieve'] = Array();
$hook_array['after_retrieve'][] = Array(
 1,
 'Filter dropdown by security group',
 'custom/modules/MPC_Job_Requirements/FilterDropdownHook.php',
 'FilterDropdownHook',
 'filterDropdownValues'
);

I found this in the document. Update field value based on a backend calculation . But this works based on the value of another field. Is there anyway we can make this work on page load itself instead of depending on another field?

asked Nov 14, 2025 at 11:10
2
  • You should add more details to your question. What exactly is "not working". What is the actual behavior and what would you expect the behavior to be? Commented Nov 14, 2025 at 11:35
  • @mscho Question updated Commented Nov 14, 2025 at 11:46

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.