Importing Contracts into SugarCRM

sugarcrmdevelopers —  August 24, 2012

Stock SugarCRM systems do not allow users or administrators to import Contracts. I was able to do this anyway with some hacks in specific pieces of the system. This includes hacks to generated HTML in the browser on the front-end, plus back-end, not-upgrade-safe code changes that you’ll want to perform then revert/undo when you’re finished. Of course, it’s probably best to do the import in a backup system first to ensure it works like you want. You can then do the same process to your Production system or just turn the new Contract records into SQL INSERT statements to manually place in the live system.

For this write-up, I was working with version 6.4.2. The changes are really just to help the system define the $bean or the $_focus of the import process.

  1. As an SugarCRM Administrator, go to the Admin page and open the Import Wizard.
  2. Using Firefox, Firebug or your Chrome developer tools, adjust an existing module option from the dropdown list (e.g. Accounts) to Contracts. Adjust the option’s value attribute, not just the label or text inside the option element.
  3. Select your new Contracts option and click the “Next” button.
  4. modify modules/Import/views/view.step3.php at around line 210:
    $this->bean = new Contract(); // add this line to define $this->bean
    $importable_fields = $this->bean->get_importable_fields(); // This is the where stock line picks up
  5. modify modules/Import/ImportDuplicateCheck.php:
    public function getDuplicateCheckIndexes()
    {
    $this->_focus = new Contract(); // add this to define $this->_focus before the rest of the method tries to use it
    $super_language_pack = ...
  6. modify modules/Import/Importer.php at around line 679:
    $this->bean = new Contract(); // the new line to define $this->bean
    $importable_fields = $this->bean->get_importable_fields();
    
  7. Now jump back to your browser. Click through and conduct normal mappings and import process.

This is largely unrelated, but for this customer, I then had to relate the data I had imported as the field reference_code to the Products table.

insert into producttemplates_contracts_c
(id,date_modified,deleted,producttemplates_contractsproducttemplates_ida,producttemplates_contractscontracts_idb)
select contracts.id,NOW(),0,product_templates.id,contracts.id from contracts
join product_templates on contracts.reference_code = product_templates.name;