Enabling import on a custom module in Sugar 5.0

bsoremsugar —  June 11, 2008 — 3 Comments

So you’ve created a new module in Sugar 5.0 with Module Builder, but now you want to import records into that module. Unfortunately in Sugar 5.0, the import function is not automatically enabled for new custom modules. We have addressed this issue in the upcoming Sugar 5.1 but that doesn’t help you today.

For those of you working with Sugar 5.0, here is a link to a sample module where I enabled the import function. You will need to take a look at the code to see how to do the same for your custom modules. I built this in Sugar Community Edition, so it will only install on Sugar 5.0.0 CE. However the approach is exactly the same for the Sugar Professional and Enterprise Editions.

Details
This module package contains a very basic module called “Work”. I built this module in Module Builder (only took 2 minutes, gotta love MB!) based on the Issue template.

When you unzip the module package, you will see directories called EnableImport, icons and SugarModules. Everything in the icons and SugarModules directories is exactly what you get when you create a module with Module Builder and publish the module package.

The EnableImport directory is where I put the necessary code to enable the import function. This directory contains some sub-directories and five files. I will explain those five files below. I also modified the manifest.php for this package to copy over the required files for enabling import and adding in the menu item on the Work module.

Required Files

  1. EnableImportmenusImport_zz_Work.php – This file is used by the manifest.php to add the Import item to the Work module’s shortcuts menu.
  2. EnableImportmodulesImportconfig.php – This file registers the Work module (zz_Work) as a module that can be imported.
    NOTE:
    This is the one out-of-the-box file that you must modify which means this change is not upgrade-safe. You will need to manually merge the one-line change in this file back into your code when ever you do upgrades in the future.
  3. EnableImportmodulesImportImportzz_Work.php – Contains the logic for actually doing the import. If you need to do any special logic (data manipulation, creating special relationships, etc), you will create special functions in this file that get executed at import.
  4. EnableImportmoduleszz_Workfield_arrays.php - This file is necessary but unfortunately a relic from the past. Up until Sugar 5.1, the Import module does not use the standard vardefs for defining a module’s required fields but rather keys off of this field_arrays.php file that we used back in Sugar 1.0 and 2.0. So you will need to register all of your module’s required fields in this file otherwise your import will fail. Thankfully Sugar 5.1 finally puts this dependency to rest.
  5. EnableImportmoduleszz_WorkImport.php – This file actually calls the Import module code when you click on the Import button.

On a final note, be sure to take a look through the manifest.php file for this package to see how I modified it to install these required files.

Have fun and let me know how this works for you.

Clint

3 responses to Enabling import on a custom module in Sugar 5.0

  1. 

    Thanks Clint, works great!

    Your fields array looks funny though.
    $fields_array['Quinn_Brokers']
    should read
    $fields_array['zz_Work']
    and have different fields:)

    Adam

  2. 

    Adam, thanks for the feedback. I’ve updated the sample module. I also changed the link above to point to the forum post that describes in more detail how to use this sample module.

  3. 

    I have upgraded to 5.2.0e and the custom import functionality for a custom module no longer works. Any ideas?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s