Book Image

Implementing SugarCRM 5.x

Book Image

Implementing SugarCRM 5.x

Overview of this book

SugarCRM is a popular customer relationship management system. It is an ideal way for small-medium business to try out a CRM system without committing large sums of money. Although SugarCRM is carefully designed for ease of use, attaining measurable business gains requires careful planning and research. This book will give you all the information you need to start using this powerful CRM system. It is the definitive guide to implementing SugarCRM. Whether you are wondering exactly what benefits CRM can bring or you have already learned about CRM systems but have yet to implement one or you're working with SugarCRM already, this book will show you how to get maximum benefit from this exciting product. It demonstrates how to install SugarCRM and also how to get the most out of it by customizing it and integrating CRM into your organization as per your needs. Focused on the needs of the enterprise, this book provides a solution-driven approach for both business and IT specialists to get the most from this powerful and popular Open Source application. It begins with a general discussion about CRM. You will then learn the benefits of such systems, and then explore SugarCRM and its unique value. You will then go through the guidelines for installing and making deployment selections that are set out alongside information for identifying, planning, and applying customizations. Training guidelines and ongoing administrative tasks will be discussed as you progress further into the book. A brief overview of SugarCRM 6.0 is provided at the end of the book.
Table of Contents (19 chapters)
Implementing SugarCRM 5.x
Credits
About the Authors
About the Reviewer
Preface

Making changes to SugarCRM modules


Before you begin customizing your system, you should take a moment to identify the necessary changes and plan them accordingly.

For starters, you should methodically go through all the SugarCRM modules that you intend to use or are using, and then examine all the terminology (field labels, tab names, and drop-down values) used within the system by default.

The objective of the exercise is to identify all the areas within the application that require modification to match your organization's lexicon. Along the way you may also identify other types of changes that you would like to apply. For example, you might wish to change the behavior of a default field from a regular text field to a drop-down field. In other cases, you may find a need to add a new field to track additional attributes for a record.

Write down the full set of modifications that you identify and keep good track of them until they have all been addressed. Consult with your peers on the CRM implementation team to make sure everyone agrees on the necessary changes.

Once you have identified the changes that you need to make, you will want to start applying them to your system.

Non-upgrade safe and upgrade safe

Before we further discuss the process of customizing the system, it is important to comprehend a critical point regarding the flexibility and extensibility of SugarCRM.

Being an open source application means that all of the code is accessible and can be adjusted to suit your needs. However, making such changes presents a problem—upgrades to SugarCRM will not honor those modifications and you will need to re-apply them manually every time you need to upgrade the system. These types of modifications are termed as non-upgrade safe, and usually involve modifications to files found in the include, cache, or modules folders of your installation (among other folders).

You will find that often times, there are multiple ways of applying a specific modification to SugarCRM. Sometimes the non-upgrade safe approach seems the more appropriate or simpler solution. However, unless you intend to make fundamental changes to the internal workings of SugarCRM, it is unlikely that you actually need to make these types of modifications to obtain your goal. It is generally advised that you steer away from making non-upgrade safe modifications to avoid future problems and hassles.

SugarCRM offers a variety of tools and techniques that allow you to make a wide range of customizations in an upgrade safe manner. This latter term refers to the ability to make changes to the system in such a way that future upgrades do not cause harm or create situations where you need to re-apply them.

This section describes the various customization tools that allow you to make upgrade safe customizations. Through their use, you will be to accomplish goals such as adding new fields, change drop-down list values, perform actions based on user initiated events, and so on.

Let us begin by looking at the customization Studio. To access it, you need to go to the Admin area of your SugarCRM installation and click on Studio in the Developer Tools section.

Customization Studio

The customization Studio (shown in the following screenshot) allows you to apply a wide range of customizations. Some of the changes that you can make using this tool include the following:

  • Layout modifications

  • Label changes

  • Adding/removing custom fields

The preceding image demonstrates the customization Studio. Notice the listing of modules on the left-hand side and the additional tools accessible at the bottom of the screen. If you expand one of the folders on the left panel, you will see a variety of additional choices. A description of these choices is as follows:

  • Labels: Allows you to modify labels within the corresponding module. It can be used to make modifications to the labels for fields and subpanel titles.

  • Fields: Tool for adding, removing, or modifying custom fields. Label changes are also permitted. Default fields cannot be modified through this tool, beyond field label changes.

  • Relationships: Describes the established links between the current module and other modules within the system.

  • Layouts: Modifications to the various views that make up a module can be made by selecting the appropriate view. For example, EditView to modify the edit view screen. You also have the ability to modify the search and quick create screens.

  • Subpanels: Used to customize the subpanels displayed on the detail view screen of the current module. Notice that the activities and history subpanels are not accessible. This is due to the fact that the mechanics used to generate them are drastically different than those generating the other subpanels.

To use these tools, simply click on them and the Studio screen will be updated to reflect the selected option. For example, let us go through the process of adding a custom field to the Accounts module.

Assuming that you are already in Studio, expand the Accounts folder in the Modules section on the left-hand side of the screen. Next, click on Fields to view the list of currently defined fields. Had our goal been to modify an existing field, we would simply click on it from the list that is currently displayed. However, our goal is to create a new field, so we must now click on the Add button. The following screen should then appear:

There are a few important items to note about this screen. First, SugarCRM allows you to select from a wide variety of field types, including text, integer, drop-down, checkbox, and so on. For our example, we will choose TextField. Fill in the remaining fields with the following parameters:

Data Type: TextField

Field Name: test

Display Label: Test

Click on the Save button after entering the aforementioned parameters to commit the field. It is important to understand that although the field is now part of the accounts module (and database structure); you will not be able to see the field within the module until you place it on one of the layouts. Thus the process of adding a field is actually twofold, involving the definition of the field, and secondly, the placing of the field on the necessary layouts to make it available for editing or visible to the user. To complete the process, let us place the field on the EditView layout for the Accounts module.

Begin by expanding the Layouts folder below the Fields option on the left-hand side of Studio. Click on EditView and you should see a screen similar to the following:

You must first find or create an empty filler area on the layout where you can place the field. To create a new filler area, you can simply drag the New Row component from the toolbox on the left to a desired area on one of the existing panels. The end result should resemble the following (the new row was inserted above the existing Campaign field):

If you prefer to place the field on a new section or panel on the EditView, you will want to first use the New Panel component and place it on the EditView layout. Once you have created the new filler area, place the field on the view by dragging it from the toolbox and onto one of the empty filler areas.

You must now instruct SugarCRM to apply the changes to the system. To do so, click on the Save & Deploy button. You can verify that the changes were indeed applied by navigating to the edit view screen of an existing account or by creating a new account. In case you are wondering about the function of the Save button, it is used to save your modifications, but does not apply the changes to the system. This option is helpful for customizations that require a long time to complete and should not be deployed until fully completed.

If you take a look at the detail view screen of an account, you will notice that the new custom field is not visible. The reason for this is that you only added the custom field to the EditView layout. This example serves to highlight the point that the layouts work independent of each other. Adding or removing a field from the EditView does not affect the DetailView or the ListView and vice versa. To display the field on the DetailView, you must go back to Studio and modify the DetailView layout for the accounts module accordingly.

Other fields can be added using the same technique and if you would like to do so, you can also rearrange or remove already existing fields from the layout. To remove an item, access the appropriate layout in Studio, then drag the item from its current location over to the trash bin icon in the toolbox.

While working in Studio, you may have noticed a series of buttons at the bottom of the screen. They are used to access the additional customization tools, including Module Builder and Dropdown Editor. The Module Builder tool will be explored in detail later in this chapter. For now, let us examine the Dropdown Editor.

Dropdown Editor

The Dropdown Editor is a very valuable tool for the Administrator. It permits the values in all of the drop-down boxes in the system to be edited. The options presented to the user may be edited, deleted, rearranged, or new values may be defined. For example, if you enter a new Account record, you will notice there are various options to select from for the Industry field, including Apparel, Banking, Engineering, and a variety of other choices, but these may not be applicable to your business. By using the Dropdown Editor you can manipulate the order in which the values appear, as well as enter new values, or modify and remove existing values.

To edit a drop-down list, click on the Dropdown Editor button in Studio and select a name of a drop-down list to edit. If you do not know which is the appropriate list that corresponds with the drop-down field you wish to edit, carry out the following steps to identify the drop-down list:

  1. 1. Click on the Studio button

  2. 2. Select the corresponding module containing the drop-down field in question

  3. 3. Expand the folder and click on Fields

  4. 4. Click on the entry corresponding to the field in question

  5. 5. Note the value for the Drop Down List parameter

Based on the preceding image, illustrating the settings for the industry field from the accounts module, the drop-down list to modify is named industry_dom. Thus you will want to click on the industry_dom list when you access the Dropdown Editor tool.

Doing so will present the following screen:

On the preceding screen, you can add, remove, or modify entries for the selected drop-down list. To add a value, scroll to the bottom of the page and type the value into the Item Name and Display Label fields, and then click on Add. You may be wondering why there are two fields if we are typing the same value into both. The reason for the dual field technique is that it allows you to define the value to store in the database and the value to display on the screen independently. A simple example of such usage would be a scenario where you might only want to store the letter Y or N in the database, depending on whether a user chooses Yes or No, instead of storing the entire value. In this example, Y would be the Item Name and Yes would be the Display Label. Modifications can be made by clicking on the pencil icon located on the far right of the entry, while clicking on the trash icon would delete the entry.

It is also possible to rearrange the order in which the items are displayed. To rearrange them, you can drag-and-drop them to a desired location or use the Sort Ascending or Sort Descending buttons at the bottom of the screen.

Once you have finished making your changes, click on the Save button at the top. Unlike modifications to the layouts, clicking on the Save button here not only preserves your changes, but also applies them to the system.

Logic hooks

All the techniques for customizing SugarCRM that we have examined up to this point have relied upon the use of built-in tools and do not require programming expertise to use them.

Logic hooks will be our first endeavor involving customization capabilities that can only be accomplished with some programming expertise. Access to the server's file system facilitates the process, but is not required.

First and foremost, let us describe a logic hook so that you have a clearer understanding of its capabilities. A logic hook is a bit of a custom PHP code that allows you to extend SugarCRM functionality. The code that makes up a logic hook is invoked upon certain activities occurring within SugarCRM. For example, a user saving a record (existing or new), deleting a record, and other actions. In turn, the custom PHP code that those actions trigger can be programmed to do just about anything that is possible through PHP. Your main limitation would be your PHP skills.

It is important to also understand that logic hooks are designed to interact with the data, not the user and they are intended to be upgrade safe.

To further clarify this latter point, a logic hook can be programmed to perform an action, such as automatically taking a value from a record upon it being saved in SugarCRM and then copying it to a data warehouse on another server. It, however, cannot be used to prompt the user with an on screen alert or pop-up, to notify them of a problem with the copy process, its success, or any other sort of interaction. Again, the logic hook can interact with the data, but not the user.

For our example, we will create a logic hook that ensures uniformity in entering contact names within this SugarCRM system. More specifically, it enforces the fact that whenever a contact is saved, the first and last name values are always saved in proper casing. For example, if a user enters the value JOHN and DOE for the first and last name fields respectively, the values are to be stored as John and Doe upon the data being saved.

To accomplish this goal, we need to create a logic hook that automatically changes the value of the first and last name fields to proper casing. We must first create a logic hook definition file that contains information used by SugarCRM to determine not only the actions that cause the custom code to run, but also the location of the file containing the custom code that is to be run. This is a standard PHP file and can be created using your text editor of choice (Notepad, vi, and so on), but its name must always be logic_hooks.php.

The logic_hooks.php file for our example will look like the following:

<?php
$hook_version = 1;
$hook_array = Array();
$hook_array['before_save'][] = Array(1, 'NameCasing', 'custom/modules/Contacts/ProperCasing.php', 'PC', 'convertToProper');
?>

All of the preceding code is standard, except for the last line. The last line is the most critical, as it tells SugarCRM when to execute the code (before_save), which file contains the relevant code (ProperCasing.php), the name of the class containing the relevant code, and finally, the function within the class that contains the code that should be executed.

If you are wondering about the first two parameters (1 and NameCasing), they are arbitrary values which you are free to define as you see fit. The number is used to order logic hooks, for situations where you have more than one, while the second value is merely a label for the current logic hook.

Note

Additional logic hooks of the same type are added by simply duplicating this last line, and updating the various parameters that it contains.

Next, we must create the file, namely, ProperCasing.php referenced above, which will contain the PHP code that ensures the data is entered in proper case. The file will look as follows:

<?php
class PC {
function convertToProper(&$bean, $event, $arguments)
{
$bean->first_name = ucwords($bean->first_name);
$bean->last_name = ucwords($bean->last_name);
}
}
?>

You will notice that there is actually very little code necessary. The $bean reference is a method for accessing the current record and database connection. This is what allows us to examine the data in any of the fields that make up the current record in the affected module and also permits us to change its value.

The final step is to place the files in the proper location so as to instruct SugarCRM to invoke the code when a user is working with the contacts module. To do so, both the logic_hooks.php and ProperCasing.php files need to be placed in the custom/modules/Contacts folder of your installation. If the directory structure does not already exist, manually create it through Windows Explorer, FTP client, and so on. Make sure that the casing and spelling on the module names match with those found in the sugar install directory/modules/ folder.

Once the files are in the proper folder, give it a try by entering a contact with all lower case values for the first and last name fields. Watch what happens to those two fields after the record is saved.

A number of other customizations can be applied to the system by means of various PHP files. This includes changing the behavior of default and custom fields, modifications to the various screens, and so on. The best part about it is that these changes are also upgrade-safe and the ability to perform these types of changes are central to the architecture of SugarCRM, which we will now examine.

Model-View-Controller (MVC)

SugarCRM's architecture utilizes the MVC design model which in turn makes it a highly customizable application. The goal of this model is to separate the various components of the system into functional areas, including the data (Model), user interface aspects (View), and database operations (Controller). It was first introduced in the 5.0 release of SugarCRM and has made the system significantly more customizable.

Some of the potential changes you could make include the following:

  • Custom list, detail, and edit screens with special behaviors

  • Addition or removal of buttons on the various views

  • Creation of dependent drop-downs

  • Insertion of custom JavaScript

  • Suppression of specific subpanels

  • Conditional styling of data

The possibilities are virtually endless and are only limited by your imagination and programming capabilities. Let us take a look at a couple of quick examples so you can get a taste of the ease and power of this architecture.

In our first example, we will change the default behavior of the name field within the cases module from text to drop-down. This will allow us to limit the values that are assigned to the field to only those defined within a list. This is a technique that helps enforce uniformity and improves metrics.

Note that creating a drop-down field requires the specification of a drop-down list containing the values from which a user can choose. We will assume that the drop-down list to be used for this exercise is one named cases_names which was previously created using the Dropdown Editor tool.

To modify the default behavior of the name field and convert it to a drop-down, create a PHP file with the following contents:

<?php
$dictionary['Case']['fields']['name']['type']='enum';
$dictionary['Case']['fields']['name']['options']='cases_names';
?>

Save the file and name it vardefs.ext.php. Notice that the file is quite small, but rather powerful. The first line overrides the default type defined for the name field and changes it to enum, which is the value that SugarCRM uses for drop-down fields. The second line specifies the name of the drop-down list that the field should use. As mentioned earlier, the drop-down list containing the values we want to use is named cases_names.

Next, you will need to place the file in the directory named sugar install directory/custom/Extension/modules/Cases/Ext/Vardefs. Proceed to create the directory structure manually if it does not already exist, making sure to match the casing as illustrated earlier.

Lastly, the changes need to be applied to the SugarCRM system. This is accomplished by using the Repair option within the admin control panel. Login to SugarCRM as an admin level user, and then select Admin | Repair | Quick Rebuild & Repair | Repair to apply the modifications. If you do not perform this step, your modifications will not appear!

Once the repair process finishes, check your cases module and it should now reflect the name field as a drop-down field.

Let us extend this example a bit further and assume that we also want to highlight the Assigned To field by coloring its text in red when the detail view of a case is accessed. Doing so would help guide the user's eye to a critical piece of information and can be used for any other field you deem equally important.

The simplest way to accomplish this goal is to copy the default DetailView definition file (detailviewdefs.php), stored in sugar install directory/modules/Cases/metadata to sugar install directory/custom/modules/Cases/metadata. Again, if the directory structure does not already exist, create it manually.

Edit detailviewdefs.php using a text editor of your choice and locate the following:

array (
array('name' => 'case_number', 'label' => 'LBL_CASE_NUMBER'),
'assigned_user_name',
),

The preceding section corresponds with the definition of the display row containing the Assigned To value. To modify it so it displays this value in red, change the preceding code to reflect the following:

array('name' => 'case_number', 'label' => 'LBL_CASE_NUMBER'),
array('name' => 'assigned_user_name', 'customCode' => '
<span style="color: red">{$fields.assigned_user_name.value}</span>'),

The customCode section is the key to accomplishing our goal. This technique allows you to inject custom HTML/JavaScript/CSS into SugarCRM's default view configuration. Note that although we are specifically working with the DetailView, similar techniques can be used for the other views as well.

To finish the example and apply your change, make sure to once again use the Repair option within the Admin control panel.

Clearly, many things are possible by leveraging the MVC model, too many to cover within this book. Fortunately, the SugarCRM Wiki and Developer Blog contain more detailed information on this topic (as well as additional examples). You can access them at the following locations:

Module Builder

You may find that upon reviewing the SugarCRM system, it may not contain a module that is well-suited to store information that is critical to your business operations. For example, RayDoc may want to store information pertaining to the materials used for various jobs and link them to the corresponding customer entry. This would allow anyone at RayDoc to see a list of the materials used to execute a particular job.

By default, SugarCRM does not contain a natural location to store such information, but the Module Builder allows you to create a custom module to address such needs.

Using the Module Builder allows you to not only create and modify custom modules, but also allows you to link the data they contain to existing modules, or to establish relationships between them. They are especially helpful for tracking information where a one-to-many relationship exists between an existing module and the intended custom module.

The Module Builder can be accessed by opening Studio and then clicking on the Studio Builder button. If you choose to create a new module, you will notice that SugarCRM provides some templates that help cut down on the amount of work required to create it.

Custom modules can be used to track just about any type of data that your company needs. Some of those possibilities include the following:

  • Products

  • Membership information

  • Personal details, such as hobbies

A great overview of the Module Builder's capabilities is available at the following URL:

http://www.sugarcrm.com/crm/node/10024/task%3Dshow51modulebuilder/tmpl%3Dgw

Integration using SOAP and REST API

SugarCRM includes a SOAP based API that allows you or others with programming expertise to programmatically interact with the data in SugarCRM.

This is helpful for integrating the system with other applications that are already in use at your company. For example, you can use it to exchange data with your accounting system, to integrate SugarCRM with your website, and to do numerous other things. You can use the API to add, modify, delete, or read data from SugarCRM.

With the release of SugarCRM Version 5.5, additional enhancements were introduced into the API that allowed it to support Representational State Transfer (REST) and custom methods.

Detailed information and examples are available at the following SugarCRM developer website:

http://developer.sugarcrm.com