Custom search using dynamic dropdowns

I hope someone can help me out here.
I have been trying to implement a custom search, using 3 dynamically populated dropdowns. The dropdowns are populated by different functions. I have edited searchdefs.php and changed the default textbox to multiselects by specifying the ‘type’=>‘enum’ and using ‘function’=>‘get_brands’ on the first search field to populate the first ‘dropdown’. I have inserted some javascript into the searchform to turn the multiselects into dropdowns. My problem is where to place the file containing the function ‘get_brand’ so that suiteCRM can find it?
I have tried multiple places in the ‘custom/Extension’ and ‘custom/application’ directory trees. I should have been able to place my function in the compiled file ‘custom/application/Ext/Utils/custom_utils.ext.php’ or ‘include/utils/custom_utils.php’ but these locations do not work for the customised search form. These locations may work, as the documentation suggests, for custom vardefs but it certainly does not want to work for custom searchfields. I have been able to get the code to work by placing my file in the custom/Extension/application/Ext/Include folder, but this breaks suiteCRM when the ‘rebuild/repair’ option is selected from the admin panel, as this folder is technically for custom modules.
I am beyond caring about making the application ‘brittle’ for upgrades, as I just need to get the custom search with dropdowns working at this stage. I am running suiteCRM7.5
and would appreciate any help in where to place the file containing ‘get_brands’ function that is used to populate my first dropdown. The other dropdowns are populated using javascript/ajax attached to change events on the first 2 dropdowns. Thanks in advance.

I’m having the same issue, oddly enough.

I’m trying to hack the ordinary textboxes (multiselect) to turn them into ordinary select boxes in HTML. In the JavaScript I’ve had to select on id, then remove the size and multiple attributes on the HTML. That works.

But now, trying to add JavaScript to handle the onchange event is giving me some difficulty. From there I POST to a PHP file, using AJAX, and that PHP file should return some data for me to populate the select boxes with.

Where would I include a global function in PHP so SuiteCRM knows that it exists and I can call it?

Also, is anyone having difficulty with 403 Forbidden errors? Why can’t I just test my PHP file to pull some data out of MySQL by typing the URL? I’ve tried overriding with .htaccess and checked the permissions. I’ve had to use the most permissive permissions so far, which makes me uncomfortable.

Does anyone have any idea on including global functions in SuiteCRM? These are global helper functions which deal with MySQL data, I would like to be able to call them from anywhere.

Also does anyone have any idea on 403 Forbidden errors? I’ve googled this, and I’ve done everything suggested so far. Permissions with chown’ing and chmod’ing, and permissions set inside PHP files with config information.

I’m stuck, the documentation is inadequate for even simple tasks (unless I’m looking in the wrong place) and Googling doesn’t help much (for the Forbidden issue). it seems a lot of people run into this and still the suggested remedies don’t seem to work out.

Thanks for any guidance.

You are aware that all info regarding customising SugarCRM CE 6.x.x is relevant for SuiteCRM also?

Have you seen this:

Sounds like you are going about this the wrong way and trying to hack together a complicated modification without any real knowledge of how to develop on the Sugar CE framework.

If you want to include a global function in PHP you should create an entry point :

If you were wanting to add a new action to a module you would create a custom controller and add your custom action in there :

Examples of this can be seen by looking at the Projects module where I call controller functions via AJAX in: modules/Project/js/main_lib.js and modules/Project/controller.php

Also I think you should be looking at modifying these files to achieve what you are trying to do:


You are correct our developer documentation is highly inadequate as we dont have resource at the moment but also remember that any documentation regarding Sugarcrm CE is also documentation for SuiteCRM As suite is just an enhanced version of SugarCE 6.5.x

Thanks Andy. I’ll check it out.

The problem was that I had no idea what to search on in the first place. I doubt I would have thought of “custom entry points” for instance.

I want SuiteCRM to recognise a global PHP function without explicitly referring to it in the URL. I don’t want an entry point accessed like this: http://{sugar url}/index.php?entryPoint=customEntryPoint

I want to go to http://{sugar url}/ and have it pick up a global function.

Does that make sense?

Thanks again Andy.

To add a global function you may have a look here:

1 Like

Thanks for that, I can get them running fairly easily now. What is still getting me and others is how to attach a global function to a search form control.

So for instance, with searchdefs.php there might be:

$module_name = ‘AOS_Products’;
$searchdefs = [$module_name] =
array (
‘layout’ =>
‘basic_search’ =>
array (
‘name’ =>
array (
‘type’ => ‘enum’,
‘name’ => ‘name’,
‘default’ => ‘true’,
‘width’ => ‘10%’,
‘function’ =>
array (
‘name’ => ‘get_names’,
‘include’ => ‘custom/application/Ext/Utils/custom_utils.ext.php’,

So in the basic search I have a bit of JavaScript to make it a proper drop down box, a select element, and the get_names() function is supposed to grab what I want out of MySQL and print out the “foo” strings.

The function is in custom/Extension/application/Ext/Utils/myutils.php. Then I repair and rebuild, but nothing seems to happen.

I can write a simple hello world function and that echo’s some text on the page for me, within my view.list.php file in custom/modules/AOS_Products/views and that works fine. But getting a function to be called when it’s listed in searchdefs.php and getting it to populate a drop-down box of items, just echo’ing out the parts, I can’t get that working and I haven’t seen any examples.

Thanks again

Maybe you can do it with a logic hook. Have a look in the manual. There are different types of logic hooks and one of them may work for you.

So when things don’t seem to work just write a logic hook? Have some logic hooks. Maybe they’re the go-to hacks when you just need to get something done with SuiteCRM and already wasted days or weeks on it.

Maybe everyone is as confused as everyone else and nobody really knows what to do with searchdefs.php and adding a function to call in there and getting that to work.

I am sorry but I don’t understand your reaction.

I only suggested that you have a look at logic hooks which are part of the system and are legitimate ways to achieve things. Full stop. The rest is free polemics.

You are asking for help and you are receiving some help. Free help from others like you who also may need help for their own requirements.

The architecture of SugarCRM is extremely complex. And it doesn’t take a few weeks to learn, but years and, yet only to learn one part because it is impossible to master it all in detail.

Going back to your requirement, I think that logic hooks may (and I repeat “MAY”) be a solution. However there are probably different ways to achieve the same thing so, if you don’t like one thing to be investigated, just say thank you for the suggestion and pursue what you consider as a better option.

But please do not use that tone.

I apologise, it’s just so frustrating. I was letting off some steam. It wasn’t directed at anyone.

I’ll add a disclaimer to my posts from now on I guess. Please ignore any perceived or actual negative or other tone in my writing. None is intended. I’m a frustrated programmer and under a huge amount of pressure because SuiteCRM isn’t really usable within a few weeks. Especially for non-trivial SuiteCRM tasks.

Such is the life of a programmer, eh?


OK. No problem.

Maybe you can have a look here:

Possibly you could get there some extra hints towards solving your issue.

I couldn’t get any of that working. Maybe I’m rushing and I’ve missed a few things. But good old hacks work for simple tasks.

When the page list.view.php loads for example, inject some JS that mods the fields and does an AJAX request to populate the fields easily. I’ve also just removed the value for onclick= as the page loads with JS for the basic search button so it runs the code I want. Not the best way or the SuiteCRM way but it does work.

Also, if a subquery doesn’t work out, you can log every query in MySQL and check it out. Then hack as necessary in the PHP where you can match on the DB field name. That makes SuiteCRM behave and you can make something simple work quickly. Not recommended for most things, but if you don’t have a week to get a simple basic search working, then a hack like this might well be what you need for the moment.