Sugar Developer Blog

Importing into custom modules in 5.1

27 Aug, 2008
Posted By: John Mertic

The Import functionality in Sugar has had tremendous overhaul in Sugar 5.1 to make it a more robust and more user-friendly tool. Among the many improvements made is the ability to leverage the import tool very easily for custom modules.

Enable the module for import

To begin with, enabling a module for import can be easily done through Module Builder. When creating or editing a module’s properties, an new option entitled ‘Importing’ has been added. By checking this option, the import utility will be enabled for the module.

Module Builder showing the \

When you deploy the newly created package, a new option will appear in the left sidebar called “Import”, which will trigger the built-in Import function for the module.

You can also manually enable Importing for a module with two simple changes to your code. The first change is to the module’s bean file, where you’ll need to add the line of code below inside the bean class.

var $importable = true;

Next, you’ll need to add a line similar to what’s below into the Menu.php file, to add the left sidebar menu option that allows a user to import into the module.

if(ACLController::checkAccess('<<module name>>', 'import', true))
$module_menu[]=Array(
"index.php?module=Import&action=Step1&import_module=<<module name>>&return_module=<<module name>>&return_action=index",
$app_strings['LBL_IMPORT'],"Import", '<<module name>>');

Controlling the importable fields

You can also have fine-grained control over the fields you wish to import by optionally disabling a field from being imported into or requiring a field to be specified in the import file. Again, this can be controlled from Module Builder in the properties for each field. You can also set this option for custom fields you to the existing core modules through Studio.

Module Builder adding a new field with the \

The Importable option has three possible values: “Yes” indicates that you can import into the field and “No” indicates you can’t. In addition, setting it to “Required” forces users to specify a value for that field when importing.

You can also set this value manually in the vardefs, by setting the ‘importable’ option for the field you wish to change. SugarCRM assumes the field is importable, but not required, if no option is set ( the equivalent of the ‘Yes’ value of the importable flag as shown above ).

'new_text' => array (
'required' => false,
'name' => 'new_text',
'vname' => 'LBL_NEW_TEXT',
'type' => 'varchar',
'massupdate' => 0,
'comments' => '',
'help' => '',
'importable' => 'false', // don't allow importing into this field
'duplicate_merge' => 'disabled',
'duplicate_merge_dom_value' => '0',
'audited' => 0,
'reportable' => 1,
'len' => '25',
),
'new_text_2' => array (
'required' => false,
'name' => 'new_text_2',
'vname' => 'LBL_NEW_TEXT_2',
'type' => 'varchar',
'massupdate' => 0,
'comments' => '',
'help' => '',
'importable' => 'required', // this field is required for importing
'duplicate_merge' => 'disabled',
'duplicate_merge_dom_value' => '0',
'audited' => 0,
'reportable' => 1,
'len' => '25',
),

The improvements to the Import module in SugarCRM 5.1 allow you to easily leverage the powerful import utility with a few simple changes to your existing modules.

Tags: ,

Leave a Reply

Have feedback for us? Drop us a line.
Terms & Conditions | Privacy | Trademark Info | Contact Info | FAQs | SugarCRM Inc.© 2004 - 2009 All rights reserved.