Let the platform do the work

Enabling Importing for Custom Modules

Overview

When designing a custom module in Module Builder, you have the option to enable importing for the module. If the custom module is deployed without enabling this option, it is not recommended that you redeploy the module since any changes made in Studio and potentially other areas of the application could be lost. This article will cover how to enable importing for custom modules via a code-level change to preserve any additional configurations made to the module since being deployed from Module Builder.

Steps to Complete

To enable importing for your custom module, you must modify certain PHP files depending on the version of Sugar that you have. Please note that the instructions below apply to custom modules created via Admin > Module Builder and are not applicable to any stock modules which come out-of-the-box with Sugar. All of the directory paths are relative to the root directory of Sugar on the web server and require you to replace the <module_key> and <module_name> variables with appropriate values for your situation. For instance, if your module is installed in the directory of ./modules/abc_custom_module/ then the <module_key> would be abc and <module_name> would be custom_module.

  1. Edit the ./modules/<module_key>_<module_name>/<module_key>_<module_name>_sugar.php file in your Sugar file system.
  2. Around line 24 of the file, locate and change public $importable = false; to public $importable = true;.
  3. Save your changes to the file.
  4. Next, edit the ./modules/<module_key>_<module_name>/clients/base/menus/header/header.php file which should look similar to this:
    $viewdefs[$moduleName]['base']['menu']['header'] = array(
      array( 
        'route' => "#$moduleName/create", 
        'label' => 'LNK_NEW_RECORD',
        'acl_action' => 'create',
        'acl_module' => $moduleName,
        'icon' => 'fa-plus',
      ),
      array(
        'route' => "#$moduleName",
        'label' => 'LNK_LIST',
        'acl_action' => 'list',
        'acl_module' => $moduleName,
        'icon' => 'fa-bars',
      ),
    );
  5. Add the following line to the end of the file after the last  ), but before the ending );:
    array(
     'route' => "#bwc/index.php?module=Import&action=Step1&import_module=$moduleName&return_module=$moduleName&return_action=index",
     'label' => 'LBL_IMPORT',
     'acl_action' => 'import',
     'acl_module' => $moduleName,
     'icon' => 'icon-upload',
     ),
  6. Save your changes to the file. The updated file should then look similar to this:
    $viewdefs[$moduleName]['base']['menu']['header'] = array(
      array( 
        'route' => "#$moduleName/create", 
        'label' => 'LNK_NEW_RECORD',
        'acl_action' => 'create',
        'acl_module' => $moduleName,
        'icon' => 'fa-plus',
      ),
      array(
        'route' => "#$moduleName",
        'label' => 'LNK_LIST',
        'acl_action' => 'list',
        'acl_module' => $moduleName,
        'icon' => 'fa-bars',
      ),
      array(
        'route' => "#bwc/index.php?module=Import&action=Step1&import_module=$moduleName&return_module=$moduleName&return_action=index",
        'label' => 'LBL_IMPORT',
        'acl_action' => 'import',
        'acl_module' => $moduleName,
        'icon' => 'icon-upload',
     ),
    );

Once the necessary changes have been made, log into Sugar and navigate to Admin > Repair and perform a "Quick Repair and Rebuild". This will rebuild the cached files to fully implement the changes. 

Application

After making these changes, the "Import {Module Name}" option will appear in the Actions menu of the custom module's module tab. Simply click the triangle in the module tab, then select the Import option to create or update records for your custom module. For instructions on using Sugar's Import tool, please refer to the Import documentation.

KB ImportCustom Menu2