Data Model Customization In SugarCRM

This is the third in a series of articles introducing SugarCRM’s Module Builder to create custom modules representing custom objects (blog writers and blog posts), and we will now learn how to customize the data model representing our blog writer object.

In SugarCRM, logged in as Admin user, go to Admin>Module builder. On the left pane tree menu, click on the package you created (we called it Blog), containing the two modules - writers and posts. Click on writers to expand it, and click on ‘Fields’ icon. You will see a list of fields that are already part of the writers object. We will need to add some new fields (click on the ‘Add Field’ button), that better describe a writer object. You will notice that the writers module (screenshot below) has several fields under the ‘Person’ section, and none under the Writers section. That is because when we created the module, it ‘inherited’ fields from the Person type. Fields we will add now will be added under the Writers section.

Field properties

As you may know from working with other information systems, each object field has properties. Common field properties include name, label, type (string,integer,date etc.), length and required/optional. The most interesting property is type. SugarCRM provides us with a wide range of field types, which become very handy when defining simple as well as exotic objects.

For our writers module, we will add the following fields:

1. No. of posts - a numerator counting the number of posts published by the writer.

2. Subject - the subject the writer writes about. Possible values : technology, finance, environment. A writer can write about more than one subject, so multi-selection should be possible for this field.

3. Post Fees - the amount of money the blog owner pays each writer for a single post.

We selected these fields to demonstrate the flexibility provided by SugarCRM Module Builder in defining types of fields. Obviously, there are many other fields we need to create to properly represent the writer object.

Field Types

1. For the ‘number of posts’ field, we will select the Integer type ( assuming our writer will not write half or quarter post…). In this case, we would need the field to be auto-incremented when a new post is published by this writer. We will accomplish that later by using PHP code. Other properties of an Integer type in SugarCRM are help text that appears next to the filed, a default value and minimum and maximum values. There are also several ‘administrative’ properties that are shared by all field types: whether the field is required or not, should it be audited (e.g. every change in the filed value is logged to a log file) and field behavior during imports.

2. The ’subject’ field is an interesting one, because we need to allow multiple values to be assigned to a single field. That is not as trivial as it sounds, as databases usually allow a single field to have a a single value. To implement multi-value fields in a database, one is required to implement a separate table to hold the 1 to many relationship between the field and its values. In our case, SugarCRM does all that stuff behind the scenes.

Another important feature of the module builder is drop-down lists. Any type of thinkable object would contain fields with a limited list of possible value. The best example - countries. Almost any information system holds lists of countries. This list is well defined and limited, so we need to offer this list to the users to select from, and not allow him to type the country value by himself (interestingly enough, Sugar does not provide an out of the box drop down list of countries..). Our ’subject’ field will contain a drop down list with 3 values - technology, finance and environment. The user will be able to choose 1,2 or all 3 values.

3. You will almost certainly have to maintain information related to money in your CRM system. Be it for quotations, sales forecasts or reporting, monetary fields should be well supported. For our ‘post fees’ field (assuming a blog writer is paid by post), we will select either an integer or more likely, a decimal type, along with a currency field. Combined, these two field can represent any amount of money in any currency. Currencies are also maintainable in SugarCRM, including currency rates (can be maintained from Admin->Currencies).

The next post in this series will explain how to create custom user interfaces using SugarCRM Module Builder.

Comments

Leave a Reply