Tuesday, June 23, 2009

SugarCRM Troubleshooting Simplified - Part II

Expanding on my previous post covering some troubleshooting tips for SugarCRM, this article will focus on potential configuration hazards.
A number of problems relating to SugarCRM can be directly attributed to improper PHP configurations. These problems tend to manifest themselves in a variety of ways, but a few common scenarios include:
  • Blank page when using Module Loader, Upgrade Wizard or Installer
  • Blank page after System Check or after accepting license at install time
  • Inability to upload files, i.e. Notes attachments, module or patch install packages, etc.
If you are experiencing any of the above described problems, you should first confirm that you are using a version of PHP that is supported for use with your version of SugarCRM.
Perhaps the most helpful tool for not only obtaining the version number of your PHP install, but other information as well, is to use the built-in phpinf0() function.
In order to use it, create a PHP file with the following text in it:
Place the file in the root directory of your SugarCRM install and then view it in your browser. The output will display the configuration settings of your PHP installation.
A page detailing your PHP version number and configuration settings will be generated when you view the PHP file in your browser. If it does not, the likely source of the problem is that PHP is not enabled for your site or directory, which likely also explains why your SugarCRM system may not be functioning.
Once you have the version number for PHP, you can verify it is a supported one by matching it up against the official SugarCRM supported platforms matrix. Make sure that you match it up against the matrix that corresponds with your version of SugarCRM as different versions have differing requirements.
Other important PHP settings relating to SugarCRM include:
(Recommended settings specified in parantheses)
  • memory_limit (64M)
  • session.save_path
  • upload_max_filesize (30M)
Remember, if you make a change to your PHP.INI to adjust any of these or other settings, you must restart your web service in order to apply the changes.

Friday, June 5, 2009

Hit Milestone

Just hit my 2,000th post on the SugarCRM Community Forums, joining a small group of community members sharing that same milestone.
Three thoughts immediately cross my mind:
  • I may not be dedicating enough time to my running
  • This might explain why my books to read queue is almost as long as my Netflix queue
  • The keyboard on my laptop broke, but thankfully, it was within the warranty period
Tomorrow I'll run an extra mile to celebrate. LOL

Monday, June 1, 2009

Simple SugarCRM Logic Hook Example

Logic hooks are one of the most powerful features of SugarCRM, however, their power also introduces complexities. If you are not familiar with this feature, more detailed information on the topic can be found on the SugarCRM Developer site.
In a nutshell, their power lies in the fact that they allow a programmer to extend SugarCRM functionality with custom code which in turn can be designed do just about anything.
Some capabilities include:
  • Modifying values on a record before it is saved to the database
  • Updating other databases based on actions performed within SugarCRM
  • Conditional sending of e-mail messages
A common task that users will want to accomplish with a logic hook is to interact with the database at some level when an action is performed within SugarCRM.
Consider the following scenario:
Workflow requirements dictate that the Assigned To value of a Case always match the Assigned To value specified on the Account record to which the Case is linked.
Thus, we must do two things:

1. Determine the assigned_user_id value of the parent Account record
2. Ensure that the assigned_user_id value of the Case record matches that of the parent Account

Both steps are easily accomplished via a logic hook and demonstrate the feature's ability to query the database as well as modify the current record's values.
We will use the before_save hook in this example, causing it to trigger whenever a Case record is committed to the database.

First we'll need to create a file called logic_hooks.php and put the following PHP code in it:
$hook_version = 1;
$hook_array = Array();
$hook_array['before_save'][] = Array(1, 'assignUser', 'custom/modules/Cases/autoUserAssignment.php', 'UserAssignment', 'updateCase');

Make sure to save the file to the [sugar]/custom/modules/Cases directory.

The logic_hooks.php file described above provides the parameters necessary for SugarCRM to know not only when the custom code should execute, but also where the code can be found.
Notice the reference to the file autoUserAssignment.php. That is the file that SugarCRM will examine for the custom code that needs to be executed when the appropriate conditions are met. 

Create a PHP file by that name and store it in the [sugar]/custom/modules/Cases directory.
Add the following to said file:


class UserAssignment {
      function updateCase(&$bean, $event, $arguments) 

           //Query ACCOUNTS table for assigned_user_id value of parent Account
           $case_id = $bean->id;
           $acct_id = $bean->account_id;
$query = "SELECT accts.assigned_user_id FROM accounts accts ";
$query .= "WHERE = '$acct_id' LIMIT 1";
$results = $bean->db->query($query, true);
$row = $bean->db->fetchByAssoc($results);
$user_id = $row['assigned_user_id'];

           //Change assigned_user_id value on Case
           $bean->assigned_user_id = $user_id;

That should do it! 

From now on, whenever a user clicks Save on a Case, SugarCRM will automatically set the Assigned To value to match that of the related Account.