Thursday, February 18, 2010

SugarCRM Customization: Styled Data

Want to make something stand out on the DetailView of your records? Here is a quick way of doing that: add some CSS styling to it.

The best part is that it is very simple to apply this effect.  In order to apply styling to a value (say, to make it show up in red) for a field named interest_c, add the following line to the field's definition array in detailviewdefs.php stored in custom/modules/Contacts/metadata

'customCode' => '<span style="color: red">{$fields.interest_c.value}</span>',

SugarCRM Logic Hook: Proper Casing Fields

Sorry for my absence. Been meaning to write, but been caught up with other cool things.  Anyway, wanted to post a quick and easy one that many might find helpful. 

One of the biggest challenges with a database application such as SugarCRM is ensuring that data is entered in a uniform manner by its various users. The use of drop down and multi-select fields helps address this challenge quite well, but said field types cannot be used in all places. 

A good example of where they cannot be used is the Last Name field on a Contact entry. However, at the same time, it would be nice to be able to enforce some uniformity in the field's values, for example, ensure that names are being entered in proper case.  

This need provides us with a great opportunity to once again highlight the power of logic hooks. In our example, the uniformity we want to introduce is the proper casing of the text entered into the Last Name field. Thus, values that are typed in as "doe" are automatically corrected and saved to the database as "Doe."

A logic hook is the perfect solution as it is transparent to the user and easily extended to support other fields.

Lets take a look at how we can accomplish the above...