id
stringlengths
14
16
text
stringlengths
33
5.27k
source
stringlengths
105
270
c91a5b84b54a-18
'required' => true, 'reportable' => true, 'duplicate_on_record_copy' => 'no', 'comment' => 'Unique identifier', 'mandatory_fetch' => true, ), 'deleted' => array( 'name' => 'deleted', 'vname' => 'LBL_DELETED', 'type' => 'bool', 'default' => '0', 'reportable' => false, 'duplicate_on_record_copy' => 'no', 'comment' => 'Record deletion indicator' ) ), 'indices' => array( 'id' => array(
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Models/SugarBean/Implementing_Custom_SugarBean_Templates/index.html
c91a5b84b54a-19
), 'indices' => array( 'id' => array( 'name' => 'idx_' . preg_replace('/[^a-z0-9_\-]/i', '', strtolower($module)) . '_pk', 'type' => 'primary', 'fields' => array('id') ), 'deleted' => array( 'name' => 'idx_' . strtolower($table_name) . '_id_del', 'type' => 'index', 'fields' => array('id', 'deleted') ) ), 'duplicate_check' => array( 'enabled' => false ) );
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Models/SugarBean/Implementing_Custom_SugarBean_Templates/index.html
c91a5b84b54a-20
'enabled' => false ) ); Note: This vardef template also shrinks the SugarBean template down even further, by defaulting auditing, favorites, and activity stream to false. Using a Custom Bean Template
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Models/SugarBean/Implementing_Custom_SugarBean_Templates/index.html
c91a5b84b54a-21
With the custom SugarBean template in place, we can now implement the template on a custom module. Typically if you deployed a module from Module Builder, there would be two classes generated by Sugar, "custom_Module_sugar" and "custom_Module". The "_sugar" generated class extends from the Bean template that was selected in Module Builder, and the primary Bean class is what is utilized in the system and where your development would take place. For the above example template that is created, the assumption is that you are writing the Bean class, rather than using the generated classes by Module Builder, or at the very least removing the intermediary "_sugar" class generated by Module Builder and extending from the desired template. If you deployed a module via Module Builder, and are going to switch to a custom template, please note that some of the stock templates contain internal logic for the setup of fields for that template and that would need to be duplicated if you intend to continue using
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Models/SugarBean/Implementing_Custom_SugarBean_Templates/index.html
c91a5b84b54a-22
setup of fields for that template and that would need to be duplicated if you intend to continue using those fields. The stock templates, located in ./include/SugarObjects/templates/, are available for your reference to copy over any of the required logic to your custom Bean class. With all that being said, let us take a look at a custom Bean class that extends from our custom template.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Models/SugarBean/Implementing_Custom_SugarBean_Templates/index.html
c91a5b84b54a-23
This example will use the "custom_Module" module which is a module that will be used for Tagging records. Since the module is just storing tags, a slimmed down Bean works well as we only need a "name" field to store those tags. The following class would implement the custom Bean template created above. ./modules/custom_Module/custom_Module.php <?php require_once 'custom/include/SugarObjects/templates/bare/BareBean.php'; class custom_Module extends BareBean { public $new_schema = true; public $module_dir = 'custom_Module'; public $object_name = 'custom_Module'; public $table_name = 'custom_Module'; public $importable = true; public $id; public $name; public $deleted;
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Models/SugarBean/Implementing_Custom_SugarBean_Templates/index.html
c91a5b84b54a-24
public $id; public $name; public $deleted; public function __construct(){ parent::__construct(); } public function bean_implements($interface){ switch($interface){ case 'ACL': return true; } return false; } } With the modules SugarBean class created, the other thing that needs to be implemented is the vardefs.php file: ./modules/custom_Module/vardefs.php <?php $module = 'custom_Module'; $table_name = strtolower($module); $dictionary[$module] = array( 'table' => $table_name, 'fields' => array( 'name' => array( 'name' => 'name',
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Models/SugarBean/Implementing_Custom_SugarBean_Templates/index.html
c91a5b84b54a-25
'name' => array( 'name' => 'name', 'vname' => 'LBL_NAME', 'type' => 'username', 'link' => true, 'dbType' => 'varchar', 'len' => 255, 'unified_search' => true, 'full_text_search' => array(), 'required' => true, 'importable' => 'required', 'duplicate_merge' => 'enabled', //'duplicate_merge_dom_value' => '3', 'merge_filter' => 'selected', 'duplicate_on_record_copy' => 'always', ), ), 'relationships' => array ( ), 'optimistic_locking' => false,
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Models/SugarBean/Implementing_Custom_SugarBean_Templates/index.html
c91a5b84b54a-26
), 'optimistic_locking' => false, 'unified_search' => false, ); VardefManager::createVardef( $module, $module, //Specify the bare template to be used to create the vardefs array('bare') ); With these files implemented, the "custom_Module" module would implement the "bare" template we created. Creating Custom Vardef Templates
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Models/SugarBean/Implementing_Custom_SugarBean_Templates/index.html
c91a5b84b54a-27
Creating Custom Vardef Templates For some customizations, you might not need a SugarBean template as you may not be implementing logic that needs to be shared across multiple module's Bean classes. However, you may have field definitions that are common across multiple modules that would be beneficial for implementing as Vardef Templates. To create a vardef template, a file as follows, ./custom/include/SugarObjects/implements/<template_name>/vardefs.php.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Models/SugarBean/Implementing_Custom_SugarBean_Templates/index.html
c91a5b84b54a-28
Continuing on with our example custom_Module module from above, we might want to have a creation date on this custom tags module since our 'bare' SugarBean template does not come with one by default. We could easily just add one in the modules vardef file, but for our example purposes, we know that we will use our 'bare' SugarBean template on other customizations, and on some of those we might also want to include a creation date. To implement the vardef template for the creation date field, we create the following: ./custom/include/SugarObjects/implements/date_entered/vardefs.php <?php $vardefs = array( 'fields' => array( 'date_entered' => array( 'name' => 'date_entered',
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Models/SugarBean/Implementing_Custom_SugarBean_Templates/index.html
c91a5b84b54a-29
'name' => 'date_entered', 'vname' => 'LBL_DATE_ENTERED', 'type' => 'datetime', 'group' => 'created_by_name', 'comment' => 'Date record created', 'enable_range_search' => true, 'options' => 'date_range_search_dom', 'studio' => array( 'portaleditview' => false, ), 'duplicate_on_record_copy' => 'no', 'readonly' => true, 'massupdate' => false, 'full_text_search' => array( 'enabled' => true, 'searchable' => false ), ) ), 'indices' => array(
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Models/SugarBean/Implementing_Custom_SugarBean_Templates/index.html
c91a5b84b54a-30
), ) ), 'indices' => array( 'date_entered' => array( 'name' => 'idx_' . strtolower($table_name) . '_date_entered', 'type' => 'index', 'fields' => array('date_entered') ) ) ); Using a Custom Vardef Template Once the vardef template is in place, you can use the template by adding it to the 'uses' array property of your module vardefs. Continuing with our example module custom_Module, we can update the vardefs file as follows: ./modules/custom_Module/vardefs.php <?php $module = 'custom_Module'; $table_name = strtolower($module); $dictionary[$module] = array(
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Models/SugarBean/Implementing_Custom_SugarBean_Templates/index.html
c91a5b84b54a-31
$dictionary[$module] = array( 'table' => $table_name, 'fields' => array( 'name' => array( 'name' => 'name', 'vname' => 'LBL_NAME', 'type' => 'username', 'link' => true, 'dbType' => 'varchar', 'len' => 255, 'unified_search' => true, 'full_text_search' => array(), 'required' => true, 'importable' => 'required', 'duplicate_merge' => 'enabled', //'duplicate_merge_dom_value' => '3', 'merge_filter' => 'selected', 'duplicate_on_record_copy' => 'always',
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Models/SugarBean/Implementing_Custom_SugarBean_Templates/index.html
c91a5b84b54a-32
'duplicate_on_record_copy' => 'always', ), ), 'relationships' => array ( ), //Add the desired vardef templates to this list 'uses' => array( 'date_entered' ), 'optimistic_locking' => false, 'unified_search' => false, ); VardefManager::createVardef( $module, $module, //Specify the bare template to be used to create the vardefs array('bare') ); After a Quick Repair and Rebuild, a SQL statement should be generated to update the table of the module with the new date_entered field that was added to the vardefs using the vardef template.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Models/SugarBean/Implementing_Custom_SugarBean_Templates/index.html
c91a5b84b54a-33
Last modified: 2023-02-03 21:04:03
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Models/SugarBean/Implementing_Custom_SugarBean_Templates/index.html
02f83923b328-0
Customizing Core SugarBeans Overview This article covers how to extend core SugarBean objects to implement custom code. This can be used to alter the stock assignment notification message or to add logic to change the default modules behavior. Customizing a Core Module The best approach to customizing a core SugarBean object is to become familiar with how the core Bean operates and only modify the bean logic where absolutely necessary. After understanding where you wish to make your customization in the module Bean class, you can extend the class in the custom directory. In order to avoid duplicating code from the core Bean class, it is always best to extend the class rather than duplicate the class to the custom directory.  Extending the SugarBean For this example, we will look at modifying the Leads SugarBean object. To extend the core Leads bean, create the following file:
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Models/SugarBean/Customizing_Core_SugarBeans/index.html
02f83923b328-1
./custom/modules/Leads/CustomLead.php <?php require_once 'modules/Leads/Lead.php'; class CustomLead extends Lead { /** * Saves the record * - You can use this method to implement before save or after save logic * * @param bool $check_notify * @return string */ function save($check_notify = FALSE) { $id = parent::save($check_notify); return $id; } /** * Retrieves a record * - You can use this method to set properties when fetching a bean * * @param string $id * @param bool $encode * @param bool $deleted * @return $this */
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Models/SugarBean/Customizing_Core_SugarBeans/index.html
02f83923b328-2
* @param bool $deleted * @return $this */ function retrieve($id = '-1', $encode = true, $deleted = true) { return parent::retrieve($id, $encode, $deleted); } /** * Calls custom logic events * - You can use this method to watch for specific logic hook events * * @param $event * @param array $arguments */ function call_custom_logic($event, $arguments = array()) { parent::call_custom_logic($event, $arguments); } } Register the Custom Class
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Models/SugarBean/Customizing_Core_SugarBeans/index.html
02f83923b328-3
} } Register the Custom Class Once the custom SugarBean class file has been created, register that class to be used by the module so that the BeanFactory knows which class to use. To register the class you will create the following file in the ./custom/Extension/ directory: ./custom/Extension/application/Ext/Include/customLead.php <?php /** * The $objectList array, maps the module name to the Vardef property * By default only a few core modules have this defined, since their Class/Object names differs from their Vardef Property **/ $objectList['Leads'] = 'Lead'; // $beanList maps the Bean/Module name to the Class name $beanList['Leads'] = 'CustomLead'; // $beanFiles maps the Class name to the PHP Class file
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Models/SugarBean/Customizing_Core_SugarBeans/index.html
02f83923b328-4
// $beanFiles maps the Class name to the PHP Class file $beanFiles['CustomLead'] = 'custom/modules/Leads/CustomLead.php'; Note: The $objectList array only needs to be set on those modules that do not have it set already. You can view ./include/modules.php to see the core modules that have it defined already. Once the registration file is in place, go to Admin > Repairs, and run a Quick Repair and Rebuild so that the system starts using the custom class. Things to Note Overriding a core SugarBean class comes with some caveats: The custom class is only used when the product core code uses the BeanFactory.Â
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Models/SugarBean/Customizing_Core_SugarBeans/index.html
02f83923b328-5
For most circumstances, Sugar is set up to use BeanFactory, however, legacy code or specific logic that is pairs core modules together may use direct calls to a core SugarBean class, which would then cause the custom class to not be used. In those scenarios, it is recommended to use a logic look instead. Extending the Cases module doesn't affect the email Import process. If the $objectList property is not defined for the module, the custom object will be used, however, things like Studio will no longer work correctly. For the example above, we defined the $objectList property for the Leads module to make sure that Studio continued working as expected. Without this definition, if you navigate to Admin > Studio, fields and relationships will not render properly. Last modified: 2023-02-03 21:04:03
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Models/SugarBean/Customizing_Core_SugarBeans/index.html
3c6c24473e60-0
BeanFactory Overview The BeanFactory class, located in ./data/BeanFactory.php, is used for loading an instance of a SugarBean. This class should be used any time you are creating or retrieving bean objects. It will automatically handle any classes required for the bean. Creating a SugarBean Object newBean() To create a new, empty SugarBean, use the newBean() method. This method is typically used when creating a new record for a module or to call properties of the module's bean object. $bean = BeanFactory::newBean($module); newBeanByName() Used to fetch a bean by its beanList name. $bean = BeanFactory::newBeanByName($name); Retrieving a SugarBean Object getBean()
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Models/BeanFactory/index.html
3c6c24473e60-1
Retrieving a SugarBean Object getBean() The getBean() method can be used to retrieve a specific record from the database. If a record id is not passed, a new bean object will be created. $bean = BeanFactory::getBean($module, $record_id); Note: Disabling row-level security when accessing a bean should be set to true only when it is absolutely necessary to bypass security, for example when updating a Lead record from a custom Entry Point. An example of accessing the bean while bypassing row security is: $bean = BeanFactory::getBean($module, $record_id, array('disable_row_level_security' => true)); retrieveBean()
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Models/BeanFactory/index.html
3c6c24473e60-2
retrieveBean() The retrieveBean() method can also be used to retrieve a specific record from the database. The difference between this method and getBean() is that null will be returned instead of an empty bean object if the retrieve fails. $bean = BeanFactory::retrieveBean($module, $record_id); Note: Disabling row-level security when accessing a bean should be set to true only when it is absolutely necessary to bypass security, for example, when updating a Lead record from a custom Entry Point. An example of accessing the bean while bypassing row security is: $bean = BeanFactory::retrieveBean($module, $record_id, array('disable_row_level_security' => true)); Retrieving Module Keys getObjectName()
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Models/BeanFactory/index.html
3c6c24473e60-3
Retrieving Module Keys getObjectName() The getObjectName() method will return the object name / dictionary key for a given module. This is normally the same as the bean name, but may not be for some modules such as Cases which has a key of 'aCase' and a name of 'Case'. $moduleKey = BeanFactory::getObjectName($moduleName); getBeanName() The getBeanName() method will retrieve the bean class name given a module name. $moduleClass = BeanFactory::getBeanName($module);   Last modified: 2023-02-03 21:04:03
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Models/BeanFactory/index.html
16a5f0ac05e4-0
Fields Overview How fields interact with the various aspects of Sugar.  SugarField Widgets The SugarField widgets, located in ./include/SugarFields/Fields/ , define the data formatting and search query structure for the various field types. They also define the rendering of fields for modules running in backward compatibility mode. When creating or overriding field widgets, developers should place their customization in ./custom/include/SugarFields/Fields/. For information on how Sidecar renders fields, please refer to the fields section in our user interface documentation. Creating Custom Fields Implementation
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Fields/index.html
16a5f0ac05e4-1
Implementation All fields for a module are defined within vardefs. Within this definition, the type attribute will determine all of the logic applied to the field. For example, the Contacts module has a  'Do Not Call' field. In the vardefs, this field is defined as follows: 'do_not_call' => array ( 'name' => 'do_not_call', // the name of the field 'vname' => 'LBL_DO_NOT_CALL', // the label for the field name 'type' => 'bool', // the fields type 'default' => '0', // the fields default value 'audited'=>true, // whether the field is audited 'duplicate_on_record_copy' => 'always', // whether to duplicate the fields value when being copied
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Fields/index.html
16a5f0ac05e4-2
'comment' => 'An indicator of whether contact can be called' // admin context of the field ),
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Fields/index.html
16a5f0ac05e4-3
),  The bool type field is rendered in the UI from the ./clients/base/fields/bool/bool.js field controller which renders the appropriate handlebars template as defined by the users current view for sidecar enabled modules. When the user saves data, the controller formats the data for the API and passes it to an endpoint. Once the data is received by the server, The SugarField definition calls any additional logic in the apiSave function to format the data for saving to the database. The same concept is applied in the apiFormatField function when retrieving data from the database to be passed back to the user interface through the API. For modules running in backward compatibility mode, the bool field is rendered using the Smarty .tpl) templates located in ./include/SugarFields/Fields/Bool/.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Fields/index.html
16a5f0ac05e4-4
While the vardefs define the default type for a field, this value can be overridden in the metadata of the view rendering the field. The example being that in ./custom/modules/Contacts/clients/base/views/record/record.php, you can modify the do_not_call field array to point to a custom field type you have created. For more information on creating custom field types, please refer to Creating Custom Fields documentation.     Last modified: 2023-02-03 21:04:03
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Fields/index.html
ff21c5578934-0
Vardefs Overview Vardefs (Variable Definitions) provide the Sugar application with information about SugarBeans. Vardefs specify information on the individual fields, relationships between beans, and the indexes for a given bean.  Each module that contains a SugarBean file has a vardefs.php file located in it, which specifies the fields for that SugarBean. For example, the vardefs for the Contact bean are located in ./modules/Contacts/vardefs.php. Dictionary Array Vardef files create an array called $dictionary, which contains several entries including tables, fields, indices, and relationships. table : The name of the database table (usually, the name of the module) for this bean that contains the fields audited : Specifies whether the module has field-level auditing enabled
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/index.html
ff21c5578934-1
audited : Specifies whether the module has field-level auditing enabled duplicate_check : Determines if duplicate checking is enabled on the module, and what duplicate check strategy will be used if enabled.  fields : A list of fields and their attributes indices : A list of indexes that should be created in the database optimistic_locking : Determines whether the module has optimistic locking enabled Optimistic locking prevents loss of data by using the bean's modified date to ensure that it is not being modified simultaneously by more than one person or process. unified_search : Determines whether the module can be searched via Global Search This setting defaults to false and has no effect if all of the fields in the fields array have the 'unified_search' field attribute set to false.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/index.html
ff21c5578934-2
unified_search_default_enabled : Determines whether the module should be searched by default for new users via Global Search This setting defaults to true but has no effect if unified_search is set to false. visibility : A list of visibility classes enabled on the module Duplicate Check Array The duplicate_check array contains two properties, that control if duplicate checking is enabled on the module, and which duplicate check strategy will be used to check for duplicates. The two properties for the array are as follows: Name Type Description enabled Boolean Specifies whether or not the Bean is utilizing the duplicate check framework <class_name> Array
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/index.html
ff21c5578934-3
<class_name> Array <class_name> is the name of the duplicate check strategy class that is handling the duplicate checking. It is set to an array of Metadata, specific to the strategy defined in the key. Review the Duplicate Check Framework for further information. Fields Array The fields array contains one array for each field in the SugarBean. At the top level of this array, the key is the name of the field, and the value is an array of attributes about that field. The list of possible attributes are as follows: name : The name of the field vname : The language pack ID for the label of this field type : The type of the attribute assigned_user_name : A linked user name bool : A boolean value char : A character array date : A date value with no time datetime : A date and time email : An email address field
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/index.html
ff21c5578934-4
datetime : A date and time email : An email address field enum : An enumeration (dropdown list from the language pack) id : A database GUID image : A photo-type field link : A link through an explicit relationship. This attribute should only be used when working with related fields. It does not make the field render as a link. name : A non-database field type that concatenates other field values phone : A phone number field to utilize with callto:// links relate : Related bean team_list : A team-based ID text : A text area field url : A hyperlinked field on the detail view varchar : A variable-sized string table : The database table the field comes from. The table attribute is only needed to join fields from another table outside of the module in focus. isnull : Whether the field can contain a null value
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/index.html
ff21c5578934-5
isnull : Whether the field can contain a null value len : The length of the field (number of characters if a string) options : The name of the enumeration (dropdown list) in the language pack for the field dbtype : The database type of the field (if different than the type) reportable : Determines whether the field will be available in the Reports and Workflow modules default : The default value for this field. Default values for the record are populated by default on create for the record view (for Sidecar modules) and edit view (for Legacy modules) layout but can be modified by users. The Default Value option is available for all data type fields except HTML, Image, Flex Relate, and Relate. massupdate : Determines whether the field will show up in the mass-update panel on its module's list view
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/index.html
ff21c5578934-6
Some field types are restricted from mass update regardless of this setting. rname : For relate-type fields, the field from the related variable that contains the text id_name : For relate-type fields, the field from the bean that stores the ID for the related bean source : Set to 'non-db' if the field value does not come from the database The source attribute can be used for calculated values or values retrieved in some other way. sort_on : The field to sort by if multiple fields are used in the presentation of field's information fields : For concatenated values, an array containing the fields that are concatenated db_concat_fields : For concatenated values, an array containing the fields to concatenate in the database unified_search : Determines whether the field can be searched via Global Search
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/index.html
ff21c5578934-7
This has no effect if the dictionary array setting 'unified_search' is not set to true. enable_range_search : For date, datetime, and numeric fields, determines if this field should be searchable by range in module searches dependency : Allows a field to have a predefined formula to control the field's visibility studio : Controls the visibility of the field in the Studio editor If set to false, then the field will not appear in any studio screens for the module. Otherwise, you may specify an Array of view keys from which the field's visibility should be removed (e.g. array('listview'=>false) will hide the field in the listview layout screen). The following example illustrates a standard ID field for a bean: 'id' => array ( 'name' => 'id', 'vname' => 'LBL_ID',
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/index.html
ff21c5578934-8
'vname' => 'LBL_ID', 'type' => 'id', 'required' => true, ), Indices Array This array contains a list of arrays that are used to create indices in the database. The fields in this array are: name : The unique name of the index type : The type of index (primary, unique, or index) fields : An ordered array of the fields to index source : Set to 'non-db' if you are creating an index for added application functionality such as duplication checking on imports The following example creates a primary index called 'userspk' on the 'id' column: array( 'name' => 'userspk', 'type' => 'primary', 'fields'=> array('id') ), Relationships Array
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/index.html
ff21c5578934-9
'fields'=> array('id') ), Relationships Array The relationships array specifies relationships between beans. Like the indices array entries, it is a list of names with array values. 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 (e.g. one-to-many, many-to-many) relationship_role_column : The type of relationship role
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/index.html
ff21c5578934-10
relationship_role_column : The type of relationship role relationship_role_column_value : Defines the unique identifier for the relationship role The following example creates a relationship between a contact and the contact that they report to. The reports_to_id field maps to the id of the record that belongs to the higher-ranked contact. This is a one-to-many relationship in that a contact may only report to one person, but many people may report to the same contact. 'contact_direct_reports' => array( 'lhs_module' => 'Contacts', 'lhs_table' => 'contacts', 'lhs_key' => 'id', 'rhs_module' => 'Contacts', 'rhs_table' => 'contacts', 'rhs_key' => 'reports_to_id',
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/index.html
ff21c5578934-11
'rhs_key' => 'reports_to_id', 'relationship_type' => 'one-to-many' ), Visibility Array The visibility array specifies the row level visibility classes that are enabled on the bean. Each entry in the array, is a key-value pair, where the key is the name of the Visibility class and the value is set to boolean True. More information on configuring custom Visibility strategies can be found in the Architecture section under Visibility Framework. Extending Vardefs More information about extending and overriding vardefs can be found in the Extensions Framework documentation under Vardefs.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/index.html
ff21c5578934-12
TopicsManually Creating Custom FieldsThe most common way to create custom fields in Sugar is via Studio inside the application. This page describes how to use the ModuleInstaller class or vardef extensions as alternative methods of creating custom fields.Specifying Custom Indexes for Import Duplicate CheckingWhen importing records to Sugar via the Import Wizard, users can select which of the mapped fields they would like to use to perform a duplicate check and thereby avoid creating duplicate records. This article explains how to enable an additional field or set of fields for selection in this step.Working With IndexesSugar provides a simple method for creating custom indexes through the vardef framework. Indexes can be built on one or more fields within a module. Indexes can be saved down to the database level or made available only in the application for functions such as Import Duplicate Checking. Last modified: 2023-02-03 21:04:03
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/index.html
25207871d447-0
Working With Indexes Overview Sugar provides a simple method for creating custom indexes through the vardef framework. Indexes can be built on one or more fields within a module. Indexes can be saved down to the database level or made available only in the application for functions such as Import Duplicate Checking. Index Metadata Indexes have the following metadata options that can be configured per index: Key Value Description  name string A Unique identifier to define the index. Best practices recommend indexes start with idx and contain the suffix cstm to avoid conflicting with a stock index.  Note : Some databases have restrictions on the length of index names. Please check with your database vendor to avoid any issues. type string   All indexes should use the type of "index" fields array A PHP array of the fields for the index to utilize  source string
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/Working_With_Indexes/index.html
25207871d447-1
array A PHP array of the fields for the index to utilize  source string Specify as "non-db" to avoid creating the index in the database Creating Indexes Stock indexes are initially defined in the module's vardefs file under the indices array. For reference, you can find them using the vardef path of your module. The path will be  ./modules/<module>/vardefs.php. Custom indexes should  be created using the Extension Framework. First, create a PHP file in the extension directory of your desired module. The path should similar to ./custom/Extension/modules/<module>/Ext/Vardefs/<name>.php. In the new file, add the appropriate $dictionary reference to define the custom index: <?php
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/Working_With_Indexes/index.html
25207871d447-2
<?php $dictionary['<module>']['indices'][] = array( 'name' => '<index name>', 'type' => 'index', 'fields' => array( 'field1', 'field2', ) ); Note : For performance reasons, it is not recommended to create an index on a single field unless the source is set to non-db. Once installed,you will need to navigate to Admin > Repair > Quick Repair and Rebuild to enable the custom index. You will need to execute any scripts generated by the rebuild process. Removing Indexes Stock indexes are initially defined in the module's vardefs file under the indices array. For reference, you can find them using the vardef path of your module. The path will be ./modules/<module>/vardefs.php.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/Working_With_Indexes/index.html
25207871d447-3
Stock indexes should be removed using the Extension Framework. First, create a PHP file in the extension directory of your desired module. The path should similar to ./custom/Extension/modules/<module>/Ext/Vardefs/<name>.php. In the new file, loop through the existing 'indices' sub-array of the $dictionary to locate the stock index to remove, and use unset() to remove it from the array. Example The following is an example to remove the idx_calls_date_start index from the Call module's vardefs. First, create ./custom/Extension/modules/Calls/Ext/Vardefs/remove_idx_calls_date_start.php from the root directory of your Sugar installation on the web server. When creating the file, keep in mind the following requirements:
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/Working_With_Indexes/index.html
25207871d447-4
The name of the file is not important, as long as it ends with a .php extension. The rest of the directory path is case sensitive so be sure to create the directories as shown. If you are removing the index for a module other than Calls, then substitute the corresponding directory name with that module. Ensure that the entire directory path and file have the correct ownership and sufficient permissions for the web server to access the file. The contents of the file should look similar to the following code: <?php $call_indexes = $dictionary['Call']['indices']; $remove_index = "idx_calls_date_start"; foreach($call_indexes as $index_key => $index_item) { if( $index_item['name'] == $remove_index ) {
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/Working_With_Indexes/index.html
25207871d447-5
if( $index_item['name'] == $remove_index ) { unset($dictionary['Call']['indices'][$index_key]); } } Note : Removing the reference to the index from the module's indices array does not actually remove the index from the module's database table. Removing the reference from the indices array ensures that the index is not added back to the module's database table when performing any future Quick Repair and Rebuilds. The database index must be removed directly at the database level. On MySQL, with the current example, this could be done with a query like: ALTER TABLE calls DROP INDEX idx_calls_date_start; Once installed,you will need to navigate to Admin > Repair > Quick Repair and Rebuild to remove the index from the $dictionary array. You will need to execute any scripts generated by the rebuilding process.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/Working_With_Indexes/index.html
25207871d447-6
Creating Indexes for Import Duplicate Checking When importing records to Sugar via the Import Wizard, users can select which of the mapped fields they would like to use to perform a duplicate check and thereby avoid creating duplicate records. The following instructions explain how to enable an additional field or set of fields for selection in this step. Example The following is an example to add the home phone field to the Contact module's duplicate check. First, create ./custom/Extension/modules/Contacts/Ext/Vardefs/custom_import_index.php from the root directory of your Sugar installation on the web server. When creating the file, keep in mind the following requirements: The name of the file is not important, as long as it ends with a .php extension. The rest of the directory path is case sensitive so be sure to create the directories as shown.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/Working_With_Indexes/index.html
25207871d447-7
The rest of the directory path is case sensitive so be sure to create the directories as shown. If you are creating the import index for a module other than Contacts, then substitute the corresponding directory name with that module. Ensure that the entire directory path and file have the correct ownership and sufficient permissions for the web server to access the file. The contents of the file should look similar to the following code: <?php $dictionary['Contact']['indices'][] = array( 'name' => 'idx_home_phone_cstm', 'type' => 'index', 'fields' => array( 0 => 'phone_home', ), 'source' => 'non-db', );
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/Working_With_Indexes/index.html
25207871d447-8
), 'source' => 'non-db', ); Please note that the module name in line 2 of the code is singular (i.e. Contact, not Contacts). If you are unsure of what to enter for the module name, you can verify the name by opening the ./cache/modules/<module_name>/<module_name>vardefs.php file. The second line of that file will have text like the following: $GLOBALS["dictionary"]["Contact"] = array (...); The parameter following "dictionary" is the same parameter you should use in the file defining the custom index. To verify duplicates against a combination of fields (i.e. duplicates will only be flagged if the values of multiple fields match those of an existing record), then simply add the desired fields to the 'fields' array in the code example.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/Working_With_Indexes/index.html
25207871d447-9
Finally, navigate to Admin > Repair > Quick Repair and Rebuild to enable the custom index for duplicate verification when importing records in the module.  Last modified: 2023-02-03 21:04:03
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/Working_With_Indexes/index.html
6bbae2fbe511-0
Manually Creating Custom Fields Overview The most common way to create custom fields in Sugar is via Studio inside the application. This page describes how to use the ModuleInstaller class or vardef extensions as alternative methods of creating custom fields. Note: Sugar Sell Essentials customers do not have the ability to upload custom file packages to Sugar using Module Loader. Using ModuleInstaller to Create Custom Fields There are two ways to create a field using the ModuleInstaller class: via installer package or programmatically. An example of creating a field from a module-loadable package is explained in the Module Loader documentation,, Creating an Installable Package that Creates New Fields. The following example shows how to programmatically add custom fields using the ModuleInstaller class with the install_custom_fields() method: <?php $fields = array ( //Text array(
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/Manually_Creating_Custom_Fields/index.html
6bbae2fbe511-1
<?php $fields = array ( //Text array( 'name' => 'text_field_example', 'label' => 'LBL_TEXT_FIELD_EXAMPLE', 'type' => 'varchar', 'module' => 'Accounts', 'help' => 'Text Field Help Text', 'comment' => 'Text Field Comment Text', 'default_value' => '', 'max_size' => 255, 'required' => false, // true or false 'reportable' => true, // true or false 'audited' => false, // true or false 'importable' => 'true', // 'true', 'false', 'required' 'duplicate_merge' => false, // true or false ), //DropDown
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/Manually_Creating_Custom_Fields/index.html
6bbae2fbe511-2
), //DropDown array( 'name' => 'dropdown_field_example', 'label' => 'LBL_DROPDOWN_FIELD_EXAMPLE', 'type' => 'enum', 'module' => 'Accounts', 'help' => 'Enum Field Help Text', 'comment' => 'Enum Field Comment Text', 'ext1' => 'account_type_dom', //maps to options - specify list name 'default_value' => 'Analyst', //key of entry in specified list 'mass_update' => false, // true or false 'required' => false, // true or false 'reportable' => true, // true or false 'audited' => false, // true or false
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/Manually_Creating_Custom_Fields/index.html
6bbae2fbe511-3
'audited' => false, // true or false 'importable' => 'true', // 'true', 'false' or 'required' 'duplicate_merge' => false, // true or false ), //MultiSelect array( 'name' => 'multiselect_field_example', 'label' => 'LBL_MULTISELECT_FIELD_EXAMPLE', 'type' => 'multienum', 'module' => 'Accounts', 'help' => 'Multi-Enum Field Help Text', 'comment' => 'Multi-Enum Field Comment Text', 'ext1' => 'account_type_dom', //maps to options - specify list name 'default_value' => 'Analyst', //key of entry in specified list
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/Manually_Creating_Custom_Fields/index.html
6bbae2fbe511-4
'default_value' => 'Analyst', //key of entry in specified list 'mass_update' => false, // true or false 'required' => false, // true or false 'reportable' => true, // true or false 'audited' => false, // true or false 'importable' => 'true', // 'true', 'false' or 'required' 'duplicate_merge' => false, // true or false ), //Checkbox array( 'name' => 'checkbox_field_example', 'label' => 'LBL_CHECKBOX_FIELD_EXAMPLE', 'type' => 'bool', 'module' => 'Accounts', 'default_value' => true, // true or false 'help' => 'Bool Field Help Text',
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/Manually_Creating_Custom_Fields/index.html
6bbae2fbe511-5
'help' => 'Bool Field Help Text', 'comment' => 'Bool Field Comment', 'audited' => false, // true or false 'mass_update' => false, // true or false 'duplicate_merge' => false, // true or false 'reportable' => true, // true or false 'importable' => 'true', // 'true', 'false' or 'required' ), //Date array( 'name' => 'date_field_example', 'label' => 'LBL_DATE_FIELD_EXAMPLE', 'type' => 'date', 'module' => 'Accounts', 'default_value' => '', 'help' => 'Date Field Help Text', 'comment' => 'Date Field Comment',
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/Manually_Creating_Custom_Fields/index.html
6bbae2fbe511-6
'comment' => 'Date Field Comment', 'mass_update' => false, // true or false 'required' => false, // true or false 'reportable' => true, // true or false 'audited' => false, // true or false 'duplicate_merge' => false, // true or false 'importable' => 'true', // 'true', 'false' or 'required' ), //DateTime array( 'name' => 'datetime_field_example', 'label' => 'LBL_DATETIME_FIELD_EXAMPLE', 'type' => 'datetime', 'module' => 'Accounts', 'default_value' => '', 'help' => 'DateTime Field Help Text',
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/Manually_Creating_Custom_Fields/index.html
6bbae2fbe511-7
'help' => 'DateTime Field Help Text', 'comment' => 'DateTime Field Comment', 'mass_update' => false, // true or false 'enable_range_search' => false, // true or false 'required' => false, // true or false 'reportable' => true, // true or false 'audited' => false, // true or false 'duplicate_merge' => false, // true or false 'importable' => 'true', // 'true', 'false' or 'required' ), //Encrypt array( 'name' => 'encrypt_field_example', 'label' => 'LBL_ENCRYPT_FIELD_EXAMPLE', 'type' => 'encrypt', 'module' => 'Accounts',
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/Manually_Creating_Custom_Fields/index.html
6bbae2fbe511-8
'type' => 'encrypt', 'module' => 'Accounts', 'default_value' => '', 'help' => 'Encrypt Field Help Text', 'comment' => 'Encrypt Field Comment', 'reportable' => true, // true or false 'audited' => false, // true or false 'duplicate_merge' => false, // true or false 'importable' => 'true', // 'true', 'false' or 'required' ), ); require_once('ModuleInstall/ModuleInstaller.php'); $moduleInstaller = new ModuleInstaller(); $moduleInstaller->install_custom_fields($fields); Add labels for custom fields by creating a corresponding language extension file:
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/Manually_Creating_Custom_Fields/index.html
6bbae2fbe511-9
Add labels for custom fields by creating a corresponding language extension file: ./custom/Extension/modules/Accounts/Ext/Language/en_us.<name>.php <?php $mod_strings['LBL_TEXT_FIELD_EXAMPLE'] = 'Text Field Example'; $mod_strings['LBL_DROPDOWN_FIELD_EXAMPLE'] = 'DropDown Field Example'; $mod_strings['LBL_CHECKBOX_FIELD_EXAMPLE'] = 'Checkbox Field Example'; $mod_strings['LBL_MULTISELECT_FIELD_EXAMPLE'] = 'Multi-Select Field Example'; $mod_strings['LBL_DATE_FIELD_EXAMPLE'] = 'Date Field Example';
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/Manually_Creating_Custom_Fields/index.html
6bbae2fbe511-10
$mod_strings['LBL_DATETIME_FIELD_EXAMPLE'] = 'DateTime Field Example'; $mod_strings['LBL_ENCRYPT_FIELD_EXAMPLE'] = 'Encrypt Field Example'; Finally, navigate to Admin > Repair > Quick Repair and Rebuild to make the new field available for users. Using the Vardef Extensions You should try to avoid creating your own custom fields using the vardefs as there are several caveats: If your installation does not already contain custom fields, you must manually create the custom table. Otherwise, the system will not recognize your field's custom vardef. This situation is outlined in the following section. You must run a Quick Repair and Rebuild and then execute the generated SQL after the vardef is installed.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/Manually_Creating_Custom_Fields/index.html
6bbae2fbe511-11
You must correctly define the properties of a vardef. If you miss any, the field may not work properly. Your field name must end with "_c" and have the property 'source' set to 'custom_fields'. This is required as you should not modify core tables in Sugar and it is not permitted on Sugar's cloud service. Your vardef must specify the exact indexes of the properties you want to set. For example, use:  $dictionary['<module singular>']['fields']['example_c']['name'] = 'myfield_c'; instead of $dictionary['<module singular>']['fields']['example_c'] = array(['name' => 'myfield_c');. This will help prevent the system from losing any properties when loading from the extension framework.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/Manually_Creating_Custom_Fields/index.html
6bbae2fbe511-12
The initial challenge when creating your own custom vardef is getting the system to recognize the vardef and generate the database field. This issue is illustrated with the example below: ./custom/Extension/modules/<module>/Ext/Vardefs/<file>.php <?php $dictionary['<module singular>']['fields']['example_c']['name'] = 'example_c'; $dictionary['<module singular>']['fields']['example_c']['vname'] = 'LBL_EXAMPLE_C'; $dictionary['<module singular>']['fields']['example_c']['type'] = 'varchar'; $dictionary['<module singular>']['fields']['example_c']['enforced'] = '';
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/Manually_Creating_Custom_Fields/index.html
6bbae2fbe511-13
$dictionary['<module singular>']['fields']['example_c']['dependency'] = ''; $dictionary['<module singular>']['fields']['example_c']['required'] = false; $dictionary['<module singular>']['fields']['example_c']['massupdate'] = '0'; $dictionary['<module singular>']['fields']['example_c']['default'] = ''; $dictionary['<module singular>']['fields']['example_c']['no_default'] = false; $dictionary['<module singular>']['fields']['example_c']['comments'] = 'Example Varchar Vardef';
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/Manually_Creating_Custom_Fields/index.html
6bbae2fbe511-14
$dictionary['<module singular>']['fields']['example_c']['help'] = ''; $dictionary['<module singular>']['fields']['example_c']['importable'] = 'true'; $dictionary['<module singular>']['fields']['example_c']['duplicate_merge'] = 'disabled'; $dictionary['<module singular>']['fields']['example_c']['duplicate_merge_dom_value'] = '0'; $dictionary['<module singular>']['fields']['example_c']['audited'] = false; $dictionary['<module singular>']['fields']['example_c']['reportable'] = true;
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/Manually_Creating_Custom_Fields/index.html
6bbae2fbe511-15
$dictionary['<module singular>']['fields']['example_c']['unified_search'] = false; $dictionary['<module singular>']['fields']['example_c']['merge_filter'] = 'disabled'; $dictionary['<module singular>']['fields']['example_c']['calculated'] = false; $dictionary['<module singular>']['fields']['example_c']['len'] = '255'; $dictionary['<module singular>']['fields']['example_c']['size'] = '20'; $dictionary['<module singular>']['fields']['example_c']['id'] = 'example_c';
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/Manually_Creating_Custom_Fields/index.html
6bbae2fbe511-16
$dictionary['<module singular>']['fields']['example_c']['custom_module'] = ''; //required to create the field in the _cstm table $dictionary['<module singular>']['fields']['example_c']['source'] = 'custom_fields'; Once the vardef is in place, determine whether the custom field's module already contains any other custom fields. If there are not any existing custom fields, create a corresponding record in fields_meta_data that will trigger the comparison process.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/Manually_Creating_Custom_Fields/index.html
6bbae2fbe511-17
INSERT INTO fields_meta_data (id, name, vname, comments, custom_module, type, len, required, deleted, audited, massupdate, duplicate_merge, reportable, importable) VALUES ('<module>example_c', 'example_c', 'LBL_EXAMPLE_C', 'Example Varchar Vardef', '<module>', 'varchar', 255, 0, 0, 0, 0, 0, 1, 'true'); Finally, navigate to Admin > Repair > Quick Repair and Rebuild. The system will then rebuild the extensions. After the repair, you will notice a section at the bottom stating that there are differences between the database and vardefs. Execute the scripts generated to create theSave custom field: Missing <module>_cstm Table: /*Checking Custom Fields for module : <module>*/
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/Manually_Creating_Custom_Fields/index.html
6bbae2fbe511-18
/*Checking Custom Fields for module : <module>*/ CREATE TABLE <module>_cstm (id_c char(36) NOT NULL , PRIMARY KEY (id_c)) CHARACTER SET utf8 COLLATE utf8_general_ci; Missing Columns: /*MISSING IN DATABASE - example_c - ROW*/ ALTER TABLE <module>_cstm add COLUMN example_c varchar(255) NULL ;   Last modified: 2023-02-03 21:04:03
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/Manually_Creating_Custom_Fields/index.html
9f109f6b475f-0
Specifying Custom Indexes for Import Duplicate Checking Overview When importing records to Sugar via the Import Wizard, users can select which of the mapped fields they would like to use to perform a duplicate check and thereby avoid creating duplicate records. This article explains how to enable an additional field or set of fields for selection in this step. Resolution The import wizard's duplicate check operates based on indices defined for that module. You can create a non-database index to check for a field. It is important that it is non-database as single column indices on your database can hamper overall performance. The following is an example to add the home phone field to the Contact module's duplicate check. First, create the following file from the root directory of your Sugar installation on the web server: ./custom/Extension/modules/Contacts/Ext/Vardefs/custom_import_index.php
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/Specifying_Custom_Indexes_for_Import_Duplicate_Checking/index.html
9f109f6b475f-1
When creating the file, keep in mind the following requirements: The name of the file is not important, as long as it ends with a .php extension. The rest of the directory path is case sensitive so be sure to create the directories as shown. If you are creating the import index for a module other than Contacts, then substitute the corresponding directory name with that module. Ensure that the entire directory path and file have the correct ownership and sufficient permissions for the web server to access the file. The contents of the file should look similar to the following code: <?php $dictionary['Contact']['indices'][] = array( 'name' => 'idx_home_phone_cstm', 'type' => 'index', 'fields' => array( 0 => 'phone_home', ), 'source' => 'non-db', );
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/Specifying_Custom_Indexes_for_Import_Duplicate_Checking/index.html
9f109f6b475f-2
), 'source' => 'non-db', ); Please note that the module name in line 2 of the code is singular (i.e. Contact, not Contacts). If you are unsure of what to enter for the module name, you can verify the name by opening the ./cache/modules/<module_name>/<module_name>vardefs.php file. The second line of that file will have text like the following: $GLOBALS["dictionary"]["Contact"] = array ( The parameter following "dictionary" is the same parameter you should use in the file defining the custom index. To verify duplicates against a combination of fields (i.e. duplicates will only be flagged if the values of multiple fields match those of an existing record), then simply add the desired fields to the 'fields' array in the code example.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/Specifying_Custom_Indexes_for_Import_Duplicate_Checking/index.html
9f109f6b475f-3
Finally, navigate to Admin > Repair > Quick Repair and Rebuild to enable the custom index for duplicate verification when importing records in the module. Last modified: 2023-02-03 21:04:03
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Vardefs/Specifying_Custom_Indexes_for_Import_Duplicate_Checking/index.html
a547acda630d-0
Database Overview All Sugar products support the MySQL and Microsoft SQL Server databases. Sugar Enterprise and Sugar Ultimate also support the DB2 and Oracle databases. In general, Sugar uses only common database functionality, and the application logic is embedded in the PHP code. Sugar does not use or recommend database triggers or stored procedures. This design simplifies coding and testing across different database vendors. The only implementation difference across the various supported databases is column types.  Primary Keys, Foreign Keys, and GUIDs By default, Sugar uses globally unique identification values (GUIDs) for primary keys for all database records. Sugar provides a Sugarcrm\Sugarcrm\Util\Uuid::uuid1() utility function for creating these GUIDs in the following format: aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee. The primary key's column length is 36 characters.Â
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Database/index.html
a547acda630d-1
The GUID format and value has no special meaning (relevance) in Sugar other than the ability to match records in the database. Sugar links two records (such as an Accounts record with a Contacts record) with a specified ID in the record type relationship table (e.g. accounts_contacts). Primary keys in Sugar may contain any unique string such as a GUID algorithm, a key that has some meaning (e.g. bean type first, followed by info), an external key, or auto-incrementing numbers converted to strings. Sugar chose GUIDs over auto-incrementing keys to enable easier data synchronization across databases and avoid primary-key collisions. You can also import data from a previous system with one primary key format and make all new records in Sugar use the GUID primary key format. All keys must be stored as globally unique strings with no more than 36 characters.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Database/index.html
a547acda630d-2
Notice If multiple records between modules contain matching ids, you may experience undesired behaviors within the system. To implement a new primary key method or to import data with a different primary key format (based on the existing GUID mechanism for new records), keep in mind the following rules of primary key behavior: Quote characters : Sugar expects primary keys to be string types and will format the SQL with quotes. If you change the primary key types to an integer type, SQL errors may occur since Sugar stores all ID values in quotes in the generated SQL. The database may be able to ignore this issue. MySQL running in Safe mode experiences issues, for instance.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Database/index.html
a547acda630d-3
Case sensitivity : The ID values abc and ABC are treated the same in MySQL but represent different values in Oracle. When migrating data to Sugar, some CRM systems may use case-sensitive strings as their IDs on export. If this is the case, and you are running MySQL, you must run an algorithm on the data to make sure all of the IDs are unique. One simple algorithm is to MD5 the ID values that they provide. A quick check will let you know if there is a problem. If you imported 80,000 leads and there are only 60,000 in the system, some may have been lost due to non-unique primary keys caused by case insensitivity.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Database/index.html
a547acda630d-4
Key size : Sugar only tracks the first 36 characters in the primary key. Any replacement primary key will either require changing all of the ID columns with one of an appropriate size or to make sure you do not run into any truncation or padding issues. MySQL in some versions has had issues with Sugar where the IDs were not matching because it was adding spaces to pad the row out to the full size. MySQL's handling of char and varchar padding has changed in later versions. To protect against this, make sure the GUIDs are not padded with blanks in the database by removing any leading or trailing space characters. Indexes Indexes can be defined in the main or custom vardefs.php for a module in an array under the key indices. See below for an example of defining several indices: 'indices' => array( array( 'name' => 'idx_modulename_name',
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Database/index.html
a547acda630d-5
array( 'name' => 'idx_modulename_name', 'type' => 'index', 'fields' => array('name'), ), array( 'name' => 'idx_modulename_assigned_deleted', 'type' => 'index', 'fields' => array('assigned_user_id', 'deleted'), ), ), The name of the index must start with idx_ and must be unique across the database. Possible values for type include primary for a primary key or index for a normal index. The fields list matches the column names used in the database. Doctrine
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Database/index.html
a547acda630d-6
Doctrine In order to provide robust support for Prepared Statements, which provide more security and better database access performance, Sugar 7.9 has adopted parts of Doctrine's Database Abstraction Layer, especially the QueryBuilder class, for working with prepared statements. The picture below shows how Sugar objects like DBManager and SugarQuery utilize Doctrine to provide this functionality, while still using the same toolset that has existed in Sugar.   DBManager The DBManager class will use Doctrine QueryBuilder for building INSERT and UPDATE queries. SugarQuery The SugarQuery class will use Doctrine QueryBuilder for building SELECT queries. SugarBean The SugarBean class will continue to use DBManager class for saving all fields.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Database/index.html
a547acda630d-7
The SugarBean class will continue to use DBManager class for saving all fields. TopicsDBManagerThe DBManager Object provides an interface for working with the database.SugarQuerySugarQuery, located in ./include/SugarQuery/SugarQuery.php, provides an object-oriented approach to working with the database. This allows developers to generate the applicable SQL for a Sugar system without having to know which database backend the instance is using. SugarQuery supports all databases supported by Sugar. Last modified: 2023-02-03 21:04:03
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Database/index.html
970a6d403fd8-0
SugarQuery Overview SugarQuery, located in ./include/SugarQuery/SugarQuery.php, provides an object-oriented approach to working with the database. This allows developers to generate the applicable SQL for a Sugar system without having to know which database backend the instance is using. SugarQuery supports all databases supported by Sugar. Note: SugarQuery only supports reading data from the database at this time (i.e. SELECT statements).  Setup To use SugarQuery, simply create a new SugarQuery object. $sugarQuery = new SugarQuery(); Basic Usage
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Database/SugarQuery/index.html
970a6d403fd8-1
$sugarQuery = new SugarQuery(); Basic Usage Using the SugarQuery object to retrieve records or generate SQL queries is very simple. At a minimum you need to set the Module you are working with, using the from() method, however, there are helper methods for just about any operation you would need in a SQL query. The methods listed below will outline the major methods you should consider utilizing on the SugarQuery object in order to achieve your development goals. from() The from() method is used to set the primary module the SugarQuery object will be querying from. It is also used to set some crucial options for the query, such as whether Team Security should be used or if only non-deleted records should be queried. The following example will set the SugarQuery object to query from the Accounts module. $sugarQuery->from(BeanFactory::newBean('Accounts'));
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Database/SugarQuery/index.html
970a6d403fd8-2
$sugarQuery->from(BeanFactory::newBean('Accounts')); Arguments Name Type Required Description $bean SugarBean Object true The SugarBean object for a specified module. The SugarBean object does not have to be a blank or new Bean as seen in the example above, but can be a previously instantiated SugarBean object. $options Array false An associative array that can specify any of the following options: alias - string - The alias for the module table in the generated SQL query team_security - boolean - Whether or not Team Security should be added to the generated SQL query  add_deleted - boolean - Whether or not 'deleted' = 0 should be added to Where clause of generated SQL query Returns SugarQuery Object
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Database/SugarQuery/index.html
970a6d403fd8-3
Returns SugarQuery Object Allows for method chaining on the SugarQuery object. select() The example above demonstrates the most basic example of retrieving records from a module. The select() method can be used on the SugarQuery object to specify the specific fields you wish to retrieve from the query. //Alter the Selected Fields $sugarQuery->select(array('id', 'name')); Arguments Name Type Required Description $fields Array false Sets the fields that should be added to the SELECT portion of the SQL query Returns SugarQuery_Builder_Select Object
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Database/SugarQuery/index.html
970a6d403fd8-4
Returns SugarQuery_Builder_Select Object You cannot chain SugarQuery methods off of the select() method, however, you can use the returned Select object to modify the SELECT portion of the statement. Review the SugarQuery_Builder_Select object in ./include/SugarQuery/Builder/Select.php for additional information on usage. where() To add a WHERE clause to the query, use the where() method to generate the Where object, and then use method chaining with the various helper methods to add conditions. To add a WHERE clause for records with the name field containing the letter "I", you could add the following code.  //add the where clause $sugarQuery->where()->contains('name', 'I'); Arguments None Returns SugarQuery_Builder_Where Object
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Database/SugarQuery/index.html
970a6d403fd8-5
Arguments None Returns SugarQuery_Builder_Where Object Allows for method chaining on the Where object as shown above. Review the SugarQuery Conditions documentation for a full spectrum of where() method usage. Relationships join() To add data from a related module to the SugarQuery, use the join() method. Adding to the same SugarQuery code example in this page, the following code would add the JOIN from Accounts module tables to Contacts table: //add join $sugarQuery->join('contacts'); Arguments Name Type Required Description $link_name String true The name of the relationship $options Array false   An associative array that can specify any of the following options: alias - string - The alias for the module table in the generated SQL query
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Database/SugarQuery/index.html
970a6d403fd8-6
alias - string - The alias for the module table in the generated SQL query relatedJoin - string - If joining to a secondary table (related to a related module), such as joining on Opportunities related to Contacts, when querying from Accounts, you can specify either the name of the relationship or the alias you specified for that relationship table. Returns SugarQuery_Builder_Join Object Allows for method chaining on the SugarQuery_Builder_Join Object, to add additional conditions to the WHERE clause of the SQL condition.  joinTable() If you were using the joinRaw() method in previous versions of Sugar, this is the replacement method which allows for joining to a related table in SugarQuery. Adding to the same SugarQuery code example in this page, the following code would add the JOIN from Accounts module tables to the accounts_contacts table:
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Database/SugarQuery/index.html
970a6d403fd8-7
//add join $sugarQuery->joinTable('accounts_contacts', array('alias' => 'ac'))->on() ->equalsField('accounts.id','ac.account_id') ->equals('ac.primary_account',1); Arguments Name Type Required Description $table_name String true The name of the database table to join.  $options Array false   An associative array that can specify any of the following options: alias - string - The alias for the module table in the generated SQL query Returns SugarQuery_Builder_Join Object Allows for method chaining on the SugarQuery_Builder_Join Object, to add additional conditions to the ON clause using the on() method.  Altering Results
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Database/SugarQuery/index.html
970a6d403fd8-8
Altering Results Altering the result set of a query can help the performance, as well as be crucial to finding the correct data. The following methods provide ways to limit the result set and change the order. distinct() To group the query on a field, you can use the corresponding distinct() method. //add group by $sugarQuery->distinct(true); Arguments Name Type Required Description $value Boolean true Set whether or not the DISTINCT statement should be added to the query Returns Current SugarQuery Object Allows for method chaining on the SugarQuery Object. limit() To limit the results of the query, you can use the limit() method.  //set the limit $sugarQuery->limit(10); Arguments Name Type Required Description $number Integer true
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Database/SugarQuery/index.html
970a6d403fd8-9
Arguments Name Type Required Description $number Integer true The max amount of rows that should be returned by the query Returns Current SugarQuery Object Allows for method chaining on the SugarQuery Object. offset() Adding a limit to the query limits the rows returned, however when doing so, you may need to alter the offset of the query to account for pagination or access other portions of the result set. To set an offset, you can use the offset() method. //set the offset $sugarQuery->offset(5); Arguments Name Type Required Description $number Integer true The offset amount of rows, or starting point, of the result Returns Current SugarQuery Object Allows for method chaining on the SugarQuery Object. orderBy()
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Database/SugarQuery/index.html
970a6d403fd8-10
Allows for method chaining on the SugarQuery Object. orderBy() To order the query on a field, you can use the corresponding orderBy() method. This method can be called multiple times, to add multiple fields to the order by clause of the query. //add group by $sugarQuery->orderBy('account_type'); Arguments Name Type Required Description $column String true The field you want the query to be grouped on $direction String false Sets the direction of sorting. Must be 'ASC' or 'DESC'. The default is 'DESC'. Returns Current SugarQuery Object Allows for method chaining on the SugarQuery Object. Execution
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Database/SugarQuery/index.html
970a6d403fd8-11
Current SugarQuery Object Allows for method chaining on the SugarQuery Object. Execution Once you have the SugarQuery object setup and configured for your statement, you will want to retrieve the results of the query, or simply get the generated query for the object. The following methods are used for executing the SugarQuery object. execute() To query the database for a result set, you will use the execute() method. The execute() method will retrieve the results and return them as a raw string, db object, json, or an array depending on the $type parameter. By default, results are returned as an array. An example of fetching records from an account is below: //fetch the result $result = $sugarQuery->execute(); The execute() function will return an array of results that you can iterate through as shown below: Array ( [0] => Array (
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Database/SugarQuery/index.html
970a6d403fd8-12
Array ( [0] => Array ( [id] => f39593da-3f88-3059-4f18-524b4d23d07b [name] => International Art Inc ) ) Note: An empty resultset will return an empty array. Arguments Name Type Required Description $type String false How you want the results of the Query returned. Can be one of the following options: db - Returns the result directly from the DatabaseManager resource array - Default - Returns the results as a formatted array json - Returns the results encoded as JSON Returns Default: Array. See above argument details for details on other Return options. compile()
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Database/SugarQuery/index.html
970a6d403fd8-13
compile() If you want to log the query being generated or want to output the query without running it during development, the compile() method is what should be used retrieve the Prepared Statement. You can then retrieve the Prepared Statement Object to retrieve the Parameterized SQL and the Parameters. For further information on Prepared Statement usage, see our Database documentation. //get the compiled prepared statement $preparedStmt = $sugarQuery->compile(); //Retrieve the Parameterized SQL $sql = $preparedStmt->getSQL(); //Retrieve the parameters as an array $parameters = $preparedStmt->getParameters(); Arguments No arguments Returns Object The compiled SQL Query built by the SugarQuery object.
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Database/SugarQuery/index.html
970a6d403fd8-14
No arguments Returns Object The compiled SQL Query built by the SugarQuery object. TopicsSugarQuery ConditionsLearn about the various methods that can be utilized with SugarQuery to add conditional statements to a query.Advanced TechniquesLearn about some of the advanced methods that SugarQuery has to offer, that are not as commonly used. Last modified: 2023-02-03 21:04:03
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_13.0/Data_Framework/Database/SugarQuery/index.html