Where is the code for X?

sugarcrmdevelopers —  September 26, 2008 — 1 Comment

Where is the code for X?

Like myself, many SugarCRM admins/users are not developers by trade. We buy or download SugarCRM, become professional users, and then start looking into code level customizations in order to best fit SugarCRM to the business. The first problem with code customizations that we usually run into is actually finding the code to change. In this article, I step you through how to find that elusive code.

The tools that you will need for this search are the Firefox browser, firebug extension, and any IDE that can search for code in an entire directory ( I use Aptana ).

The key to finding a starting point is to identify a unique indicator or string that you can search for. The more unique the string, the more likely that you will get a few good hits on your search instead of 100 hits on the search. Let’s look at an example.

For this example we will use a recent Sugar Forum question which was “Where is the code that generates the help button?” In order to find a starting point we will go through the steps below.

1. Open your Sugar instance in Firefox and open Firebug

2. In Firebug click the Inspect button

3. Click the help link

This will show the code behind the button in the Firebug window.

4. The next step is to identify a string that you think might be unique to this section of the product.

For example: If you were looking to generate a different link then you may look in the line and determine that the help_action would be helpful. If you were looking for the module code, then you may see that there is a help_module string and just directly go to modules/Help. Either way you instantly know a little more about the Help system than you did before. We will move forward as if we just want to change the URL or how it is generated.

5. In the IDE, execute a string search for help_action across the entire SugarCRM directory.

This search results in about 132 ( there are multiple in some files ) matches depending on your version and edition. Not as unique as we had hoped but many of the matches can be quickly ruled out. There are 6 matches against each theme file.  However we don’t want the URL to change per theme, but rather we want it to change in the core somewhere. There is a match in a file in the cache directory but that will be overwritten at some point because it is a cache file.

We are left with files in two directories which are include and modules. If we wanted the URL to do something completely different in one specific module then we might want to pick that module and start there. If we are changing the way the URL is generated throughout the system then the search results under the include directory are the best place to look. There are only three files under this folder that returned results and we now have a starting point.

This technique is not full proof and is subjective to the user. However, the act of searching through the code for one string that appears unique can assist in quickly identifying a starting point for your code search.  Knowing that the core of the application logic is in the include and modules directories is key and also knowing to ignore anything you find in the cache directory is very helpful.  For a more thorough description of the code structure in Sugar, check out the Sugar Developer Guide.

Good luck with your code searches!

One response to Where is the code for X?


    Very nice material.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s