How to add any field to Mass Update in SugarCRM / SuiteCRM

By default, SugarCRM / 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, you need to know that for several fields you’ll not add them to Mass Update from ​Studio​, but this can be done only by code.

To do this you should insert a file in custom/Extension/modules/<modulename>/Ext/Vardefs with:

<?php
$dictionary['<modulename>']['fields']['<fieldname>']['massupdate'] = true;
?>

With a “Quick Repair and Rebuild“, this will activate Mass Update for that field, given that is of one of one of Data Type allowed.

If instead we want, for example, ​to activate Mass Update of a “TextArea” field​, we must create a custom versione of the file include/MassUpdate.php.

The classic customization with a copy of the file in the “custom” folder, in this case it does not works, but we can get it with a slightly more complicated process.

First of all we need to create a CustomMassUpdate.php file that we are able to place in custom/include/CustomMassUpdate.php.

Inside this file we write:

<?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"] == 'text') {
            $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 '';
    }

}
?>

In a similar way we can manage other field types if we need to Mass Update them.

Now we need that our <modulename> uses our custom class instead of the standard one.

To do this we create a file custom/include/CustomListViewSmarty.php and we write:

<?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();
    }

}
?>

Now the last pass: we should use this class for Mass Update visualization.

Let’s got create a custom/modules/<modulename>/views/view.list.php file to extend the standard ViewList class (or it’s specific version for our module, if it’s present in modules/<modulename>/views/view.list.php) and we write:

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

if (! defined('sugarEntry') || ! sugarEntry)
    die('Not A Valid Entry Point');
require_once('custom/include/CustomListViewSmarty.php');
class <modulename>ViewList extends ViewList {
    function preDisplay() {
        $this->lv = new CustomListViewSmarty();
    }
}?>

With a “Quick Repair and Rebuild“, our code will start to work and our TextArea field will be added to Mass Update.

Note :

1. Here, <modulename> means the module name you see in the URL, for example, Contacts, Leads, Accounts, etc.
2. <fieldname> means anything as per your requirements

Hope you find this blog post helpful.

Feel free to add comments and queries, that helps us to improve the quality of posts.

You can contact us at info@infotechbuddies.com

Thank you.

Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *