Custom Controller Not Executing in Module Builder Created Module

Hello everyone,

I’m quite new to SuiteCRM and still learning the ropes, so please bear with me. I’m trying to customize the behavior of the ā€˜SM_Suppliers’ module, which I created using Module Builder. My goal is to add custom validations when saving a record, specifically for the ā€˜vat_id’ field.

I have created a controller.php file in the following path: /volume/public/legacy/custom/modules/SM_Suppliers/controller.php

The contents of my controller.php file are as follows:

<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

class CustomSM_SuppliersController extends SugarController{

    
    public function action_save(){
        LoggerManager::getLogger()->error('SM_SUppliers --> This is an error message');

        // Check if VAT ID is provided
        if (empty($_REQUEST['vat_id'])) {
            echo json_encode(['success' => false, 'message' => 'VAT ID is required.']);
            exit();
        }

        $vatId = $_REQUEST['vat_id'];

        // Query to check if VAT ID already exists
        $bean = BeanFactory::newBean('SM_Suppliers');
        $query = new SugarQuery();
        $query->from($bean);
        $query->select(['id']);
        $query->where()->equals('vat_id', $vatId);

        $results = $query->execute();

        if (!empty($results)) {
            echo json_encode(['success' => false, 'message' => 'VAT ID is already in use.']);
            exit();
        }

        parent::action_save();
            echo json_encode(['success' => true, 'message' => 'VAT ID is available.']);
    }
}
?>

Problem:

Despite the controller.php file being in the correct location and having performed a ā€œRepair and Rebuildā€ in SuiteCRM, the custom code is not executing. I don’t see the error_log() messages in the web server logs or the LoggerManager::getLogger()->error() messages in suitecrm.log.

Additional Information:

I have tried:

  • Checking the web server and SuiteCRM logs.
  • Clearing the SuiteCRM and browser cache.
  • Reviewing the file and directory permissions.
  • Adding error_log() statements for debugging.

I would appreciate any assistance in identifying the cause of this issue.

Thanks in advance.

If I am not mistaken, this is the logic selecting the controller

Maybe do some debugging there, see where it’s picking up things

For a custom module, I am not sure you need to put things in custom/modules/... you might be able to just put your controller directly where your main module code is (likely modules/SM_Suppliers ). Just be careful to back it up frequently until you are confident that using QR&R, Studio or Module Builder again doesn’t overwrite it.

1 Like

I am not sure action_save is called for a custom module.
But as this is a custom module, the easiest solution would probably be to redefine the save function:

	public function save($check_notify){
		// add you verification here

		if ($ok){
			parent::save($check_notify);
		}
		else {
			//
		}
	}

1 Like

Can you please try creating a file called ā€˜Save.php’ i.e public/legacy/custom/modules/SM_Suppliers/Save.php and put your logic directly in it without any class or a method. Just put the following line in this file and reload the page to check if it works.

<?php
 $GLOBALS['log']->debug('save logic here');
1 Like

thanks for you Response!

This is very usefull for my.

I have modified that file to get some information of what was happening and indeed my module is not called at any time.

And the worst thing is that I think that it does not make sense what the log shows:

...
   public static function getController($module)
    {
        LoggerManager::getLogger()->error('Victor:'. $module);
        $class = ucfirst($module).'Controller';
        LoggerManager::getLogger()->error('Victor:'. $class);
...

I have added a log to check what was happening and I get the following in the log:

Mon Mar 31 13:47:04 2025 [207][-none-][ERROR] Victor:Home
Mon Mar 31 13:47:04 2025 [207][-none-][ERROR] Victor:HomeController
Mon Mar 31 13:47:06 2025 [207][-none-][ERROR] Victor:Configurator
Mon Mar 31 13:47:06 2025 [207][-none-][ERROR] Victor:ConfiguratorController

I understand that I should be calling my module, maybe the error is in the routing configuration of my system (although I have not touched it as I am using the configuration that came in the docker package to avoid just a misconfiguration).

Any suggestions?

Thanks for your comment but the problem i dont have for the method inner class. The system dont call my class after suggests test @pgr

i try and not working