Author Archive

Vardefs.php in SugarCRM


2011
06.16

The vardefs are used to provide the Sugar application with information about the SugarBeans.

Each module that has a SugarBean file will have a vardefs.php file located in it. This file specifies the
fields for that SugarBean. For the Contact bean, the vardefs will be located in
sugarcrm/modules/Contacts/vardefs.php.
Vardef files create an array called “$dictionary” with a bunch of sub-values defined.
Dictionary Array

• ‘table’ = The database table for this bean
• ‘audited’ = True if this module has auditing turned on
• ‘fields’ = The list of fields and attributes about them (see below)
• ‘indices’ = A list of indexes that should be created in the database (see below)
• ‘relationships’ = A list of the relationships for this bean (see below)
• ‘optimistic_locking’ = True if this module should obey optimistic locking. Optimistic locking
uses the modified date to ensure that the bean you are working on has not been modified by
anybody else when you try and save. This prevents loss of data.
The fields array contains a bunch of arrays. It has one array for each field in the SugarBean.

Here is the list of possible attributes for fields.’name’ = The name of the field

Fields Array

• ‘vname’ = The language pack id for the label of this field. The language pack is located in the

language directory of each module and may include the main language file in includes/language.

• ‘type’ = The type of the attribute

• ‘relate’ = Related Bean (related to another table)

• ‘link’ = A link as defined by a relationship

• ‘id’ = An ID number (36 character ID number)’

• ‘datetime’ = A date and time

• ‘date’ = A date

• ‘bool’ = A boolean value

• ‘enum’ = An enumeration (drop down list from the language pack)

• ‘char’ = A character array

• ‘assigned_user_name’ = A linked user name

• ‘varchar’ = A variable sized string

• ‘text’ = A text field. Basically a ‘char’ that holds 65,535 (2

16

– 1) characters (I think)

• ‘phone’ = A phone number

• ‘email’ = An Email address

• ‘int’ = A number

• ‘function’ = Gets the value from a function

• ‘validation’ =    example. array(‘type’ => ‘isbefore’, ‘compareto’=>’date_due’),

• ‘table’ = The table this field comes from

• ‘isnull’ = Is this field allowed to be set to null? Can be set to ‘true’ or ‘false’.

• ‘len’ = The length of the field (number of characters if a string)

• ‘options’ = The name of the enumeration in the language pack for this field.  See ‘vname’ above

for details on the language pack.  This is only used for type ENUM fields.

• ‘dbtype’ = The database type of the field (if different than the ‘type’).  It seems to take the samevalues as ‘type’.

• ‘reportable’ = Should this field show up in the list of fields for the reporting module (if

applicable, PRO and ENT versions only).

• ‘required’ = true if this field is a required field

• ‘default’ = The default value for this field

• ‘massupdate’ = false if you do not want this field to show up in the mass update section at the

bottom of the list views. Defaults to true.

• ‘rname’ = (for type relate only) The field from the related variable that has the text

• ‘id_name’ = (for type relate only) The field from the bean that stores the id for the related Bean

• ‘source’ =  This can be used for calculated values or values retrieved in some other way.

• ‘nondb’ = the field value does not come from the table that the vardefs refers to. It comes

from another table, mostly “users” as this source type is mostly used to retrieve the user

name for assigned_user_id and modified_by fields and the like.

• ‘function’ = Gets the value from a function

• ‘sort_on’ => The field to sort by if multiple fields are used.

• ‘fields’ => (for concatenated values only) An array containing the fields that are concatenated.

• Example: array(0=>’first_name’, 1=>’last_name’)

• ‘db_concat_fields’=> (for concatenated values only) An array containing the fields to concatenate

in the DB

Indices Array

This array contains a list of arrays that are used to create indexes in the database.

The fields in this array are:

• ‘name’ = The name of the index. This must be unique in most databases.

• ‘type’ = The type of the index (primary or index)

• ‘fields’ = The fields to index. This is an ordered array

Relationships Array

The relationships array is used to specify relationships between Beans. Like the Indices array entries, it is

a list of names with array values.

The possible attributes of a relationship entry are:

• ‘lhs_module’ = The module on the left hand side of the relationship

• ‘lhs_table’ = The table on the left hand side of the relationship

• ‘lhs_key’ = The primary key column of the left hand side of the relationship

• ‘rhs_module’ = The module on the right hand side of the relationship

• ‘rhs_table’ = The table on the right hand side of the relationship

• ‘rhs_key’ = The primary key column of the right hand side of the relationship

• ‘relationship_type’ = The type of relationship (‘one-to-many’ or ‘many-to-many’)

Read More : http://dl.sugarforge.org/sugardocs/Notes/VardefsDocumentation/Vardefs.pdf

Populate class variables from post values in sugarcrm


2011
06.16
require_once(‘include/formbase.php’);
$focus = populateFromPost(”, $focus);
$focus->save;
1st parameter is for prefix, and 2nd is for class object.

Upgrade self customization in Sugarcrm


2011
06.16
Upgrade self customization is such customization in which if we upgrade Sugar version our customized part does not need any change or modification.
To overcome after up gradation problems we need to customize all our modules and other codes into custom folder.
If you directly have id use retrieve functionality. But if there any field value exist other than id use retrieve_by_string_fields function.
It takes an array as parameter and returns an object.
Example:
require_once(‘modules/Assets/Asset.php’);
$assetObj = new Asset();
$fieldArray = array(‘job_id’=>$_REQUEST['job_id']);
$asset = $assetObj->retrieve_by_string_fields($fieldArray);
Here array key ‘job_id’ is an existing field in asset table.

Use of entrypoint in SugarCRM


2011
06.15
Entrypoint is used when a particular file is saved outside the scope of our
project and we have to fire some functions (such as modification in our database/sending
mail etc.) based on that file events. For that have to make changes in
“include\MVC\Controller\entry_point_registry.php”. Actually file path is getting created
here w.r.t a specific action.
‘getImage’ => array(‘file’ => ‘include/SugarTheme/getImage.php’, ‘auth’ => false),
file is file path and auth is page have authorization checking or not.

Removing multiple select from search in index page in Sugarcrm


2011
06.15
Remove:
size={{$size}}
{{if $size>1}} multiple=”1”{{/if}}
From “include/SugarFields/Fields/Enum/SearchView.tpl”.