How-to add any field to Mass Update in SugarCRM CE 6.5 or SuiteCRM

Written Tuesday September 18 2018

By default, SugarCRM CE 6.5 (and also SuiteCRM) allow to Mass Update only fields of Data Types:

  • Checkbox
  • Datetime
  • Date
  • DropDown
  • Dynamic DropDown
  • Integer
  • Multiple Selection
  • Radio

However I found an ​Upgrade-Safe​ method to add any field to Mass Update.

First of all, it's possible to add to Mass Update some fields for which SuiteCRM doesn't allow to active Mass Update in Studio, like "Relate" fields.

To do that you must create a file in custom/Extension/modules/<nomemodulo>/Ext/Vardefs with:

<?php
$dictionary['<nomemodulo>']['fields']['<nomecampo>']["massupdate"] = true;
?>

Executing a "Quick Repair and Rebuild", the field will be active in Mass Update.

For some field types, however, the Mass Update is not available at all, for example for "TextArea" fields, but it's possible to manage it customizing the Mass Update itself.

First of all we create a file custom/include/CustomMassUpdate.php like this:

<?php
// Extension of class MassUpdate to allow MassUpdate of field of type TextArea

if (! defined('sugarEntry') || ! sugarEntry)
    die('Not A Valid Entry Point');

require_once('include/MassUpdate.php');

class CustomMassUpdate extends MassUpdate {

    /**
     * Override of this method to allow MassUpdate of field of type TextArea
     * @param string $displayname field label
     * @param string $field field name
     * @param bool $even even or odd
     * @return string html field data
     */
    protected function addDefault($displayname, $field, &$even) {
        if ($field["type"] == 'varchar') {
            $even = ! $even;
            $varname = $field["name"];
            $displayname = addslashes($displayname);
            $html = <<<EOQ
    <td scope="row" width="20%">$displayname</td>
    <td class="dataField" width="30%"><textarea name="$varname" style="width: 90%;" id="mass_{$varname}"></textarea></td>
EOQ;
            return $html;
        }
        else
            return '';
    }

}
?>

Then, to use this extension, we must create a file custom/include/CustomListViewSmarty.php like this:

<?php
// Extension of class ListViewSmarty to allow MassUpdate of field of type TextArea

if (! defined('sugarEntry') || ! sugarEntry)
    die('Not A Valid Entry Point');

require_once('include/ListView/ListViewSmarty.php');
require_once('custom/include/CustomMassUpdate.php');

class CustomListViewSmarty extends ListViewSmarty {

    /**
     * @return MassUpdate instance
     */
    protected function getMassUpdate() {
        return new CustomMassUpdate();
    }

}
?>

Executing a "Quick Repair and Rebuild", TextArea field should be managed in Mass Update.

Problems? Contact us for professional advices on SugarCRM CE or SuiteCRM.