SuiteCRM for Developers Released

posted in: SuiteCRM | 0


I work with SuiteCRM at my day job daily and have become quite experienced in it’s use, particularly customising and developing with SuiteCRM. However as a young project it lacks the wealth of resources that other projects have. Even the project from which it is forked could do better with documentation. There is docs, and some other good resources online but they take some searching for.

Enter SuiteCRM for Developers

I decided to write a book that covers some of the common development tasks that can be performed in SuiteCRM and provide a reference for making customisations. SuiteCRM for Developers is that book. It provides some of the knowledge that I have gathered from working with both SugarCRM and SuiteCRM and, hopefully, provides a good starting point for those wishing to develop with SuiteCRM.

Now released

I’m now pleased to announce that SuiteCRM for Developers has now been published on Leanpub. It’s available at an introductory rate of $14.99. I’m considering this version 1.0 and I plan to add additions and corrections. If there’s something you would like to see that I’ve missed or something that is wrong then feel free to Contact me.


SuiteCRM Custom Search Fields

posted in: SuiteCRM | 0


Sometimes you may want to add custom search fields to a module that do more than simply search a field. In this post we’ll be looking at how to add a custom search field which will allow searching for all accounts that have no associated contacts.

Adding the field

First off we create a copy of modules/Accounts/metadata/searchdefs.phpand place this in custom/modules/Accounts/metadata/searchdefs.php. We then add a new key to the $searchdefs ['Accounts']['layout']['basic_search']array which  will look something like:
We also need to add a language string for our new search field. This can be done by simply adding a new file at custom/Extension/modules/Accounts/Ext/Language/en_us.NoContactFilter.php:

This will give us the following:



Unfortunately, SuiteCRM displays our new search field as a dropdown rather than a checkbox, stay tuned for a future post on how to change this.


Adding the logic

Now we have a wonderful search dropdown on our Accounts list view. It doesn’t actually do anything however. Let’s change that.


We create a copy of modules/Accounts/metadata/SearchFields.phpand place this in custom/modules/Accounts/metadata/SearchFields.php in exactly the same manner as we did for searchdefs.php above. We add our new search field to the $searchFields['Accounts']  array.

It should look something like:

This creates a subquery filter type. Specifying a query type of format allows us to use {0} in our query to access the dropdown value. SuiteCRM will only display account ids that match what our subquery returns.

FROM accounts 
LEFT JOIN accounts_contacts ON ( = accounts_contacts.account_id AND accounts_contacts.deleted = 0)WHERE (NOT {0} AND IS NOT NULL) OR ({0} AND IS NULL)

We make use of this to force only accounts with contacts when “No” is selected (the NOT {0} AND IS NOT NULL part of the query) and only accounts with no contacts when “Yes” is selected (the {0} AND IS NULL part of the query).


Adding custom subqueries in this manner allows a huge amount of custom filters to be created. Have an idea for a custom filter? Have a better way of doing the above? Then let me know in the comments.

SuiteCRM Package Builder

posted in: SuiteCRM | 0

SuiteCRM package builder is a small PHP script which eases the pain of building a SuiteCRM package for installing changes to other instances. It simply requires a SuiteCRM install and a compliant manifest file.

This means you can build up the bulk of the package just by running something similar to:

suitecrmpackagebuilder /var/www/mySuiteCRMInstance/manifest.php /var/www/mySuiteCRMInstance/

It can be found on my GitHub page here: SuiteCRM Package Builder.

As always you should back up any instance before running code from a stranger on the internet.

BeanFactory Cache

posted in: SuiteCRM | 0


The BeanFactory is a great way to load and query for beans without using SQL.

For example we can load an Account with a known id:

Unexpected behaviour

However this method can cause some unexpected behaviour. Let’s look at the following example:


This produces the following output:

Enter the cache

So what is going on here?

Basically the getBean method is cached. getBean will cache at most 10 beans and drop some of the older entries based on usage. $acc2 is pulled from the cache and is therefore the same instance as $acc1. Any changes in one will be reflected in the other.

However when we load a bunch of beans our cached account drops out the BeanFactory Cache and when we fetch the bean into $acc3 we get a fresh instance from the database.