Allow System Admin users to set ‘Textfields’ as being mass update fields in SugarCRM and SuiteCRM

In my last post I showed you how to make specific fileds for specific modules mass up-datable but what if you want to make a field type mass up-datable across all modules? In the following tutorial I have used text fields as an example.

Before we start I want to make it clear that this is a Non-Upgrade Safe modification.

By default SugarCRM only allows fields of the following types to be mass up-datable :

  • Bool
  • Enum
  • Multienum
  • radioenum
  • datetime
  • date

So if you want add non mass up-datable fields or custom fields to the mass update form then you have to make some non-upgrade safe changes to the following file:

include/MassUpdate.php

Edit the getMassUpdateForm() function and add the code after this comment

/** Modification: add text fields like this */

:

if(isset($field['type']))
				{
					switch($field["type"])
					{
						case "relate":
    						    // bug 14691: avoid laying out an empty cell in the <table>
    							$handleRelationship = $this->handleRelationship($displayname, $field);
    							if ($handleRelationship != '')
    							{
    								$even = !$even;
    								$newhtml .= $handleRelationship;
    							}
							break;
						case "parent":$even = !$even; $newhtml .=$this->addParent($displayname, $field); break;
						case "int":
							if(!empty($field['massupdate']) && empty($field['auto_increment']))
							{
								$even = !$even; $newhtml .=$this->addInputType($displayname, $field);
							}
							 break;
						case "contact_id":$even = !$even; $newhtml .=$this->addContactID($displayname, $field["name"]); break;
						case "assigned_user_name":$even = !$even; $newhtml .= $this->addAssignedUserID($displayname,  $field["name"]); break;
						case "account_id":$even = !$even; $newhtml .= $this->addAccountID($displayname,  $field["name"]); break;
						case "account_name":$even = !$even; $newhtml .= $this->addAccountID($displayname,  $field["id_name"]); break;
						case "bool": $even = !$even; $newhtml .= $this->addBool($displayname,  $field["name"]); break;
						case "enum":
						case "multienum":
							if(!empty($field['isMultiSelect']))
							{
								$even = !$even; $newhtml .= $this->addStatusMulti($displayname,  $field["name"], translate($field["options"])); break;
							}else if(!empty($field['options'])) {
								$even = !$even; $newhtml .= $this->addStatus($displayname,  $field["name"], translate($field["options"])); break;
							}else if(!empty($field['function'])){
								$functionValue = $this->getFunctionValue($this->sugarbean, $field);
								$even = !$even; $newhtml .= $this->addStatus($displayname,  $field["name"], $functionValue); break;
							}
							break;
						case "radioenum":
						$even = !$even; $newhtml .= $this->addRadioenum($displayname,  $field["name"] , translate($field["options"])); break;
						case "datetimecombo":
						$even = !$even; $newhtml .= $this->addDatetime($displayname,  $field["name"]); break;
						case "datetime":
						case "date":$even = !$even; $newhtml .= $this->addDate($displayname,  $field["name"]); break;
                        /** Modification: add text fields like this */
                        case "varchar":

                            if($field['massupdate'] == 1){

                                $even = !$even; $newhtml .= $this->addTextBox($displayname,  $field["name"]);

                            } break;

                        default:
                            $newhtml .= $this->addDefault($displayname,  $field, $even); break;
                            break;
					}
				}

Note how we add the type ‘varchar’ to the switch statement. Now we add the custom function addTextBox to the bottom of the class:

public function addTextBox($displayname, $field){
        $displayname = addslashes($displayname);
        $html = <<<EOQ
	<td scope="row" width="20%">$displayname</td>
	<td class='dataField' width="30%"><input type="text" name='$field' size="12" id='{$field}' maxlength='10' value=""></td>

EOQ;
        return $html;
    }

Now if we update the vardefs for a specific text field and set ‘massupdate’ => true the field will appear in the mass update panel of the module but that’s not enough if we want system admin users to be able to add text fields to the mass update panel of a module via studio.

In order to achive this all we need to do is edit: modules/DynamicFields/templates/Fields/Forms/varchar.tpl

and add the following to the file:

<tr>
    <td class='mbLBL'>{sugar_translate module="DynamicFields" label="COLUMN_TITLE_MASS_UPDATE"}:</td>
    <td>
        {if $hideLevel < 5}
            <input type="checkbox" id="massupdate" name="massupdate" value="1" {if !empty($vardef.massupdate)}checked{/if}/>
        {else}
            <input type="checkbox" id="massupdate" name="massupdate" value="1" disabled {if !empty($vardef.massupdate)}checked{/if}/>
        {/if}
    </td>
</tr>

{include file="modules/DynamicFields/templates/Fields/Forms/coreBottom.tpl"}

Now all text fields will have the Mass Update check box available in studio.

Mass Update available on text fields

Andy
About

Software Developer from Falkirk, Central Scotland.

Posted in SugarCRM development and customisation, SugarCRM development development hints and tips, SugarCRM development tutorials
8 comments on “Allow System Admin users to set ‘Textfields’ as being mass update fields in SugarCRM and SuiteCRM
  1. luggie says:

    Hi Andy
    As soon as repair&rebuild Sugar crashes and shows nothing but a blank page. I tried again without the last two “}” after “(…)$this->addDefault($displayname, $field, $even); break; break;”
    This time the search function of Sugar didnt work at all and the “action -> masschange” option didnt appear.
    Any Ideas?

  2. Andy Andy says:

    There is a error in your code somewhere that’s why your getting a blank page. Its a fatal error, you should turn on error reporting in your php.ini file so you can see why its crashing.

  3. clar says:

    I’ve done exactly however on my accounts page there is this error:

    Notice: Undefined index: massupdate in C:\xampp\htdocs\SugarCE\include\MassUpdate.php on line 461

    i check the line on MassUpdate.php
    Line 461: if($field['massupdate'] == 1){

    $even = !$even; $newhtml .= $this->addTextBox($displayname, $field["name"]);

    } break;

    how to solve that error

    • Andy Andy says:

      That is not a real error just turn off Notices in your php.ini. Sugar is full of warnings like this unless you suppress all but fatal errors.

  4. Shiela says:

    Hi Andy, thank you for this post. The Mass update successfully appeared in the studio, did checked it, but it didn’t appeared in the mass update view. Any suggestions?

    • Andy Andy says:

      Did you run a quick repair and rebuild? Also double check for mistakes in the code if you copied it. It should work if you did it exactly as outlined.

  5. Shiela says:

    Yes Andy. Will this work even to latest version of Suitecrm?

  6. Shiela says:

    Hello Andy,thanks so much!! *tears of joy* xD

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>