Wednesday, January 26, 2011

SugarCRM Troubleshooting 101: Quick and Easy Custom Logs

Here is an easy, yet rather helpful, tip.

Suppose one needs to add some log messages to SugarCRM in order to trace a problem -- not uncommon when writing custom code such as that found in logic hooks.

How do we go about adding custom log messages so we can see what is going on?

It is actually fairly easy and only requires one line of code:

$GLOBALS['log']->fatal('My custom debug message');

There are two important items to note about this bit of code.  

First, the word fatal actually refers to the logging level.  SugarCRM allows you to select from various levels, including info, fatal and debug (the most verbose).  The level can be defined by an admin level user by simply selecting Admin > System Settings and modifying the logging level at the bottom of the screen.  Your custom message will print out only if the selected level within System Settings screen matches the level you use within this line of code.

Next, in this example, the text My custom debug message is all that would be printed by the logging engine.  It is basically a string of your liking, which can include references to variables -- either your own or those created by SugarCRM (such as $bean->id).

Consequently, log messages (custom or otherwise) are written to a file named sugarcrm.log which you can find in the root install directory of your SugarCRM instance.  If you prefer a different name for your log file, change it via the earlier referenced Systems Settings screen.

Lastly, if you are using a hosted instance, you may not have access to the root directory corresponding to your install.  To circumvent that and access your log file, select Admin > Diagnostics.

Thursday, January 6, 2011

January is Logic Hooks Month

According to the stats for this blog, logic hooks are a popular subject amongst visitors.  As such, I figure the topic would be a great way to kick off an idea of mine that I have been tossing around for a bit.

Going forward, I will select a topic of interest, or theme, on a monthly basis.  The objective: to discuss the topic at hand in further depth throughout the month, with other posts sprinkled in between for variety.

However, this idea can only work with your assistance.  

To help, simply reply to the post announcing the month's topic (e.g. this post) and suggest a facet of said topic for discussion.  For example, perhaps you have been wanting to build a logic hook to execute an SQL query, but are unsure about how to get started.  Simply share your scenario within the comments area.  

In turn, I will select one of the suggestions on a weekly basis and provide a detailed post discussing the process involved in addressing the issue.

Now, while all suggestions are welcome, there are some rules to consider:

1. For obvious reasons, I cannot create a detailed post for every suggestion, but if time permits, I will tackle more than 1 per week.  

2. Please be as clear as possible in your description of your scenario.  If the description is not clear, I will not consider it.

3. Do not post sample code or the like.  A clear description of the goal will suffice.  

4. Some scenarios may require very specific configurations, such as custom modules, etc.  I will not be able to create mirror environments for all cases, but my response will include sufficient guidance to fulfill the vast majority (if not all) of your goal.

5. Suggestions on themes for upcoming months are welcome and highly encouraged.

Thanks and now lets have the suggestions relating to logic hooks (in the comments section)!  

Wednesday, January 5, 2011

SugarCRM Customization: Case Numbers

One of the great things about helping newer members of the SugarCRM community is that they often help me remember some customization needs that are not frequently asked by others. 

A good example of this came up just a few days ago on the SugarCRM Forums when a user asked if it was possible to change the starting point for the numbering sequence on Cases.  By default, SugarCRM begins at the number 1 and automatically increments it by 1 whenever a new Case is added.  However, many users would prefer it to start at a different number.  

So, how does one change the start point?  

It is actually rather simple and requires two things: access to a MySQL administrative tool such as SQLyog, phpMyAdmin, etc. and a single SQL command.

Assuming you already have access to the administrative tool, executing the following command would do the trick for you:


Where nnn represents the starting number you wish to apply.  For example, to set the starting point to 1000, use the following command:


That is it!  Quick and easy!

Monday, January 3, 2011

SugarCRM Customization: Drop Down Fields

Looking to create a drop down field in SugarCRM?  

No problem.  Simply go to the customization Studio and add a new field of type "Drop Down," making sure to assign or create the appropriate drop down list at field creation time.

Simple enough, but that only works for custom fields.  What about changing an existing, default field so as to make it behave like a drop down.  For example, we might want to change the Subject field for Cases or the Name field for Opportunities into drop downs. 

Doing so would help us ensure uniformity in the classification of support inquiries or revenue opportunities, which in turn improves data quality and simplifies the measurement of effectiveness.  Ultimately, one of the goals of CRM technologies is to simplify the process of measuring how well your business is doing and the quality of the data in the system has a significant impact on that function.

So, how do we convert these default text fields to drop down fields?  Lets take a look.