Creating a custom field type in SuiteCRM

posted in: SuiteCRM | 0

Like a lot of SuiteCRM the field types are customisable and you can add your own types of fields. This post will explain how to add a colour picker as a custom field type.


First off we need to add the option to studio to allow creating fields of our new type. We do this by adding a new file custom/modules.DynamicFields/templates/Fields/TemplateColourPicker.php with the following contents:

Next we create the language file custom/Extensionmodules/ModuleBuilder/Ext/Language/en_us.ColourPicker.php and define the label for our new field type:


After a quick repair and rebuild this gives us the option to create a field with type “Colour Picker”:




This can then be added to views and the like through studio in the usual manner.


However our field is pretty boring and doesn’t do anything yet. Let’s give it some personality.


We’ll use TinyColorPicker to add some functionality to the field. This will get saved in a new directory in custom/include/SugarFields/Fields/ColourPicker/js/jqColorPicker.min.js


Next we’ll add two templates, one for the Detail view at custom/include/SugarFields/Fields/ColourPicker/DetailView.tpl:

and one for the Edit View at custom/include/SugarFields/Fields/ColourPicker/EditView.tpl:

After a quick repair and rebuild (and assuming the field has been added to the views). You’ll see the new field:




Setting up SuiteCRM on Digital Ocean

posted in: SuiteCRM | 0

This post will cover deploying an instance of SuiteCRM to Digital Ocean from creating the droplet to logging into SuiteCRM. If there’s enough interest I’ll do similar guides for other hosts.


First you’ll need a Digital Ocean account. If you don’t have one it’s easy to create one.


From the droplets page of your account we’ll click on the “Create Droplet” button.CreateDroplet

This will bring us to the following page, where we will do the following:


Give our new droplet a name – In this case “MySuiteCRMInstance”.

Choose a size – I’ve went with the smallest, sizes can always be increased as needed.

Choose a region – It’s best to choose a region closest to the users of the instance – London for me.

Choose an image – I’m going with Ubuntu 14.04 which is the current Long Term Support release.

Optionally you can add extra settings such as backups and add SSH keys (which is recommended).


Finally we can create our droplet. When this is done you’ll see a progress page, creating the droplet is usually pretty quick.



When this is complete you’ll be shown the droplet details page and receive an email with the details of your droplet.



You can now ssh into your droplet. For simplicity we’ll use the “Console Access” option on the droplet details page. You will need to change your password. Now is also a good time to create a new non-root user.





Now we have a fresh Ubuntu install we can begin setting up our environment for SuiteCRM.


First off we’ll do an update and upgrade of packages:

apt-get update;
apt-get upgrade;


This will prompt you to update packages. Agree with “Y”.

Next we’ll want to install the necessary packages and software. These are:

Apache – The web server that will serve up SuiteCRM.

MySQL – The database that we’ll be using

PHP5 – SuiteCRM runs on the PHP programming language.

APC – An (optional) PHP addition which will provide caching and speed up SuiteCRM.


apt-get install apache2 mysql-server php5 php5-mysql libapache2-mod-php5 php5-mcrypt php-apc php5-imap php5-curl php5-gd unzip;
php5enmod imap;
service apache2 restart;

Again you will want to agree to the install by pressing “Y”.


You’ll be prompted to supply a password for the MySQL root user, do so now.



When this finishes you can go to the IP address of your droplet in a browser and confirm that apache was installed correctly. You should an it works page headed with the following:


Next up we want to actually get an instance of SuiteCRM. We’ll use th

cd /var/www/html;
rm index.html;
unzip -q;
mv SuiteCRM-7.3.2/* .;
rm -r SuiteCRM-7.3.2;

Set permissions

chown -R www-data:www-data .;
chmod -R 755 .;
chmod -R 775 cache custom modules themes data upload config_override.php;


Now if we go to our droplets IP address we should see the SuiteCRM installation screen:


Click next and a page detailing what SuiteCRM will need for the install is displayed. Double check this screen but we should be good to go. Once again click next.


Next up will be the licence page. SuiteCRM is open source and is licenced under the AGPL. Accept this and click next.



This will prompt a system check which should pass. We’ll be presented with an option to do a custom or typical install. These are pretty similar so we’ll go with typical for simplicity.



Next we’ll be prompted to choose a database type. Our only option is Mysqli so choose that and click next.






Next we’ll provide the actual database configuration. Give your new database a name, I’ve imaginatively went with “suitecrm”. Provide the host for the database, since we’re running the database locally we can go with “localhost”.


It’s good practice to create a separate user for the SuiteCRM database so we supply a username and password for this. You can also optionally populate the database with demo data.


Next up we provide the admin user for SuiteCRM.


After this SuiteCRM will complete the install process and provide some details.


Finally you will be presented with a login screen:



Enter your username and password and you’ll be all set!


Have any issues? Let me know in the comments.

SuiteCRM Super Logger

posted in: SuiteCRM | 0

I’ve previously created a very simple module for SuiteCRM which adds coloured logging (SuiteCRM Colour Logger). I’ve now expanded it somewhat to add extra features.


It’s now called SuiteSuperLogger and allows specifying the log format in the config.


Enabling coloured logging can be done by adding

$sugar_config['suitesuperlogger']['colour'] = true;

To the config.

Altering the log format can be done by adding the following to config_override.php:

$sugar_config['suitesuperlogger']['format'] = ':date:[:pid:][:userId:][:level:][:remoteAddr:][:forwardedAddr:][:requestMethod:]:msg:';

The following placeholders are accepted and will be replaced with an appropriate value:

The date the message was logged
The process id
The logged in user id
The log level
The remote address as found in the PHP $_SERVER superglobal.
The request method (i.e. GET, POST, e.t.c.)
The actual log message


SuiteCRM Creating an Alert

posted in: SuiteCRM | 0

With the release of SuiteCRM 7.3 comes Alerts. These are displayed within SuiteCRM as a small badge in the menu bar. I.e:


Since these are just stored as beans we can add notifications by simply creating a new record with the appropriate values and saving it. For example:


Calling this can be used to create an alert for a specific user like so:



PHP Syntax Checking

posted in: General Programming | 0

The CLI to php allows checking for syntax errors using php -l I’ve created a very basic script which will recursively check folders for php files with syntax errors. It’s intended to quickly show syntax errors in a large application. It’s available here:

Simply run it and pass the path to your app:

php phpsyntaxcheck.php /path/to/php/files

Adding custom module to related to field in SuiteCRM

posted in: SuiteCRM | 0

Sometimes when you create a new module you want it to appear in the “Related To” dropdowns around SuiteCRM. This post will cover the simple method of adding modules to these dropdowns.


In this post we’ll add a fictional “Sport” module to the dropdown. We’ll end up with this:



The related to dropdown, like most in SuiteCRM can be changed by using the dropdown editor within SuiteCRM. We’re going to use the dropdown editor to add our custom module.


If you want to target the Related To module in Notes then edit the record_type_display_notes dropdown. For other related to dropdowns edit the parent_type_display.

We start by adding a new entry to the dropdown with the modules name as the “Item Name” and the display label we wish to use as the “Display Label”. I.e. in our example we’ll have

“ABC_Sport” as the “Item Name” and “Sport” as the “Display Label” as in this image:




And that’s it! SuiteCRM will use the module name to load the correct popup when searching for the module and will store this when saving the record. Your custom module can now be added to notes and the like.


Make a custom module importable

posted in: SuiteCRM | 0

If you’ve created a custom module but are getting the message “Imports aren’t set up for this module type” then it’s very easy to add this functionality to your custom module.


In the bean file modules/ABC_Your_Module/ABC_Your_Module.php simply add the line

var $importable = true;


After the class definition and you’ll be able to import this module.

SuiteCRM Missing Field Definitions

posted in: SuiteCRM | 0

If you move instances of SuiteCRM around it’s possible to have a copy of the SuiteCRM files that reference a custom field that doesn’t exist in the fields_meta_data table.

This can cause broken SQL queries since SuiteCRM will try to reference a field but won’t have it’s name. A broken query may look something like:

UPDATE my_custom_module SET name='Foo', =NULL,=NULL WHERE id='1234';

This can be fixed in one of two ways.

The first, preferred way is to get the info from the fields_meta_data table. This mysqldump command will create a file with the fields meta data:

mysqldump -uYourDBUser --insert-ignore --no-create-info -p YourDB fields_meta_data > fields_meta_data.sql

This can then be used to populate the new DB:

mysql -uYourDBUser -p YourNewDB < fields_meta_data.sql

The second is to find and remove the fields which are causing the issue. The following script will list any entries in the vardefs without a name which causes the original broken queries. Simply change the $base variable to be the path to the SuiteCRM instance you want to check and run php -f fieldcheck.php:

Once you have found the offending fields you can remove the definitions for them.


Add row buttons to the List View in SuiteCRM

posted in: SuiteCRM | 0

A previous post covered adding a button to the List View. However this was adding an action button to the list as a whole. This post will cover adding buttons for each row.

By the end of this post you will be able to add buttons such as this one:


Our example will look at the calls module. We’ll add a simple button to view the call on the calendar.

First off we will create a new non-db field in the calls module. We add the following file to custom/Extension/modules/Calls/Ext/Vardefs/ViewOnCalButton.php (we use the filename ‘ViewOnCalButton.php’ but this can be whatever you wish).


Next we add the language string for our new field. We place this file in custom/Extension/modules/Calls/Ext/Language/en_us.ViewOnCalButton.php:


In order to actually have the field display as a button we set up a logic hook to fill in the value. First we must define the logic hook in custom/Extension/modules/Calls/Ext/LogicHooks/ViewOnCal.php:

And then implement the hook itself and add it to custom/modules/Calls/ViewOnCalHook.php:

Note that we are creating a button which links to the calendar but this can do whatever actions you require. We must do a quick repair and rebuild from the admin menu in order for our changes above to take effect.


Finally we add the button to the list view. This can either be done in studio or by editing the list view defs. Let’s do this through studio:

ViewCalButton Studio


And there we have it. We now have the following:



Upon clicking we should be taken to the calendar.


Note that the above button is just an example and has a few issues that could be improved upon. If we click “View on calendar” for a call that isn’t ours we will be taken to a calendar page without the call on it. Can you see any other improvements? Let me know in the comments,

Car Reg Plate Game in Python

posted in: Games | 0

Me and my wife occasionally play a simple game when on longer car journeys. In the UK the last 3 characters in a car registration plate are letters.

by Cnbrb - Own work. Licensed under Public Domain via Wikimedia Commons.
by CnbrbOwn work. Licensed under Public Domain via Wikimedia Commons.

The aim of the game is to come up with words which start with the first letter, end with the last letter and contain the middle letter. So for the example plate in the image above we’d use SMR, a word that we could choose would be ‘speedometer (since it starts with s, ends with r and contains m’). Computers, unsurprisingly, are very good at this. Here’s an example of a super simple python script which prints matching words (this assumes you are on a Linux system, or at least a system with /usr/share/dict/words.

It can be called using python "BD51 SMR". This example outputs the following: