Daniel López Azaña

Theme

Social Media

Blog

GNU/Linux, Open Source, Cloud Computing, DevOps and more...

SugarCRM error when searching tasks related to custom modules with underscores within their names

sugarcrm-logo-100068038-large

When we create a custom module in SugarCRM (eg «grt_Providers_Contracts») and create a link or relationship between that module and one that uses the «Related to» field type such as «Tasks», we probably will want to search all the tasks related to our new module «grt_Providers_Contracts» from the simple or advanced search form from «Tasks» module.

However, there is a bug in SugarCRM that prevents us to retrieve tasks related to a custom module if that module has underscores (_) within his name, showing the following fatal error:

mod_fcgid: stderr: PHP Fatal error: require_once(): Failed opening required '' (include_path='/var/www/vhosts/daniloaz.com/subdomains/sugarcrm64/include/..:.:') in /var/www/vhosts/daniloaz.com/subdomains/sugarcrm64/data/SugarBean.php on line 3185, referer: https://sugarcrm64.daniloaz.com/index.php?module=Tasks&action=index

Cause of the problem

This is because when building the WHERE clause of the SQL statement that SugarCRM generates from the search form, SugarCRM obtains the two interconnected entities or modules from a faulty regular expression when we are dealing with «Related to» field types. That faulty regex appears few lines before line 3185 of file data/SugarBean.php and does not consider underscores that may appear in the name of such related entities:

$match = preg_match('/(^|[\s(])parent_(\w+)_(\w+)\.name/', $where, $matches);

Thus, in the specific case of our module «grt_Providers_Contracts», we may never get satisfactory search results because the name of the module that SugarCRM takes from the regular expression is «grt_Providers_Contracts_grt» instead of «grt_Providers_Contracts». This causes failure when the line 3185 from the date/SugarBean.php («require_once($beanFiles[$beanList [$joinModule]])» script is executed. A fatal error is then displayed because the $joinModule variable does have a wrong value, «grt_Contratos_Proveedores_grt», a module name wich doesn’t exist in the global module list handled by the SugarCRM instance, which is collected by the $beanList array.

As a disclaimer, the «grt_» prefix is a key I always add to the name of every new custom module, indicating the customer for which I am developing that module, so that it is unique and can not cause interference with other third-party custom modules.

Solution

The fix to this flaw is simple once you know what causes the problem, and consists in modifying the erroneous regular expression like this:

if (!strstr($where, 'grt_'))
    $match = preg_match('/(^|[\s(])parent_(\w+)_(\w+)\.name/', $where, $matches);
else
    $match = preg_match('/(^|[\s(])parent_(grt_\w+)_(grt_\w+)\.name/', $where, $matches);

Once this is done the problem is solved and we can perform searches of tasks related to our new module with no problems.

SugarCRM
Daniel López Azaña

About the author

Daniel López Azaña

Tech entrepreneur and cloud architect with over 20 years of experience transforming infrastructures and automating processes.

Specialist in AI/LLM integration, Rust and Python development, and AWS & GCP architecture. Restless mind, idea generator, and passionate about technological innovation and AI.

Related articles

plesk_8_3

ERROR: PleskFatalException – Unable to connect to database: saved admin password is incorrect.

After subscribing a new VPS server from my hosting provider, I found that although I could access to Plesk control panel properly, I was unable to access MySQL with the same admin’s user and password as used in Plesk. As a result, I couldn’t do anything with the database from the command line or in any other way. So I decided to manually change the admin user’s password via the mysql shell. After making such change I could perfectly log in to MySQL, but nevertheless the Plesk control panel stopped working, throwing the following exception:

July 1, 2012
PHP logo

I am looking for freelance PHP programmers

I am looking for freelance PHP programmers with initiative and entrepreneurial spirit to help me, first, take on the surplus of projects that my clients request to me and I can’t accept due to lack of time. On the other hand, but not least important, I would like to find reliable people to form a strong team to undertake and develop some projects I have in mind and others that someone may propose.Regarding the first scenario, I would like to establish a collaborative relationship in which I would be the interface to the customer and you would perform the analysis and programming tasks that I entrusted after reaching an agreement on the economic conditions of each job, although I ideally would establish a general fee of €X per hour reviewable if any particular case might arise. I’m also a programmer, so you will always have the help and support you need from me to carry out assigned projects. If collaboration in this first stage is successful, I will love to develop the second stage with you.

August 1, 2012
JAMstack Architecture - JavaScript APIs Markup

What is JAMstack? Modern Architecture for Ultra-Fast Websites

Discover how JAMstack revolutionizes web development with pre-generated static sites served from global CDN. Exceptional speed, improved security, unlimited scalability, and minimal hosting costs compared to traditional CMS platforms.

November 3, 2025

Comments

Be the first to comment

Submit comment