We have attempted to insert a text field for mass updating (opportunities, contacts and leads) using the code level customization and have done this correctly but after a quick repair and re build, the text filed does not appear. Any suggestions?
In my last post I showed you how to make specific fields for specific modules mass updatable but what if you want to make a field type mass updatable 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 updatable :
- Bool
- Enum
- Multienum
- radioenum
- datetime
- date
So if you want add non mass updatable 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 achieve 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.
This is really useful and I’m doing it at the moment, but could you please repost some of the sections… I think some code got lost or misformatted.
Thanks in advance!
@BusyBerlinBear I edited the post to make the code more readable, maybe that makes a difference? Some of the code might have been interpreted as markup and might have been getting lost.
Thank you! That’s perfect. I figured it anyway but it’s good to know I was going in the right direction
Searching through my notes, I found an example to achieve this but it’s upgrade-safe.
The code snippet is working perfectly. Thanks for everything