Friday, 30 August 2013

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.
Our first step is to determine if we need to define a new drop down list or if we are going to use an existing one.  

The drop down list contains the values that a user will be allowed to pick from for the field in question.  Note that the user must select a value from that list and will not be able to manually type in a random value.  As a result, the selected drop down list must contain appropriate values or we must create a new list that does.

We will assume we need to create new lists, respectively named 'cases_name_list' and 'opportunity_name_list.'  To create a new list, follow these steps:

1. Access SugarCRM as an admin level user.
2. Select Admin > Dropdown Editor
3. Click Add Dropdown

Proceed to name the list and enter the desired values.  Click Save when finished and repeat the process for the second list.

Now that the lists are ready, we need to connect them to the respective fields and instruct SugarCRM to make the fields behave like drop down fields.

To accomplish this, we need to do three things: create the PHP file with the instructions, place the file in the appropriate location within the SugarCRM install folder and lastly, execute a Repair operation within SugarCRM.

So what does the instruction file look like?  It is actually quite simple.  Create a file named vardefs.ext.php and add the following PHP code to it:

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

That is all we need for the instructions.  

Now save the file and place it in the following folder: /custom/Extension/modules/Cases/Ext/Vardefs.  If the directory does not exist, proceed to manually create it via Windows Explorer or other similar tool appropriate for your operating system.  That completes the second step.  

To finalize the process, access SugarCRM using an admin level account and select Admin > Repair > Quick Repair and Rebuild.  

Take a look at the Cases module and the name field should now display as a drop down when in edit mode.

To complete the exercise and apply the modification to the Opportunities module, make another file named vardefs.ext.php, but with the following instructions:

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

Place this version of the file in /custom/Extension/modules/Opportunities/Ext/Vardefs and rebuild!

To put value into   opportunity_name_list goto /custom/include/ and put the value there for the array of opportunity_name_list in associative array form.

Do the same for case_name_list.

No comments:

Post a Comment