您可以手动将新字段添加到 _cstm 表中,因此不必冒丢失现有数据的风险。
只需使用以下模板通过 SQL 和 PHP 添加字段(替换为您需要新字段的任何模块:
ALTER TABLE <module>_cstm add COLUMN new_field_c varchar(255) NULL;
最后的 _c 很重要,_cstm 表中的字段应该以 _c 结尾。
然后,导航到
{sugar_base_directory}/custom/Extension/modules/<module>/Ext/Vardefs
在该目录中,创建一个名为 Sugarfield_new_field_c.php 的新文件
在这个新创建的文件中,定义要添加的字段的属性(注意 $dictionary 数组中的模块名称应该是单数,例如 Prospect,而不是 Prospects):
<?php
$dictionary['<module_singular>']['fields']['new_field_c']['name'] = 'new_field_c';
$dictionary['<module_singular>']['fields']['new_field_c']['vname'] = 'LBL_NEW_FIELD_C';
$dictionary['<module_singular>']['fields']['new_field_c']['type'] = 'varchar';
$dictionary['<module_singular>']['fields']['new_field_c']['enforced'] = '';
$dictionary['<module_singular>']['fields']['new_field_c']['dependency'] = '';
$dictionary['<module_singular>']['fields']['new_field_c']['required'] = false;
$dictionary['<module_singular>']['fields']['new_field_c']['massupdate'] = '0';
$dictionary['<module_singular>']['fields']['new_field_c']['default'] = '';
$dictionary['<module_singular>']['fields']['new_field_c']['no_default'] = false;
$dictionary['<module_singular>']['fields']['new_field_c']['comments'] = 'Example Vardef';
$dictionary['<module_singular>']['fields']['new_field_c']['help'] = '';
$dictionary['<module_singular>']['fields']['new_field_c']['importable'] = 'true';
$dictionary['<module_singular>']['fields']['new_field_c']['duplicate_merge'] = 'disabled';
$dictionary['<module_singular>']['fields']['new_field_c']['duplicate_merge_dom_value'] = 0;
$dictionary['<module_singular>']['fields']['new_field_c']['audited'] = false;
$dictionary['<module_singular>']['fields']['new_field_c']['reportable'] = true;
$dictionary['<module_singular>']['fields']['new_field_c']['unified_search'] = false;
$dictionary['<module_singular>']['fields']['new_field_c']['merge_filter'] = 'disabled';
$dictionary['<module_singular>']['fields']['new_field_c']['calculated'] = false;
$dictionary['<module_singular>']['fields']['new_field_c']['len'] = '255';
$dictionary['<module_singular>']['fields']['new_field_c']['size'] = '20';
$dictionary['<module_singular>']['fields']['new_field_c']['id'] = 'new_field_c';
$dictionary['<module_singular>']['fields']['new_field_c']['custom_module'] = '<module>';
$dictionary['<module_singular>']['fields']['new_field_c']['source'] = 'custom_fields';
?>
然后,在表中插入一条相应的记录fields_meta_data
,将触发比较过程,即让 SugarCRM 知道这个新字段:
INSERT INTO fields_meta_data (id, name, vname, comments, custom_module, type, len, required, deleted, audited, massupdate, duplicate_merge, reportable, importable) VALUES ('<module>new_field_c', 'new_field_c', 'LBL_NEW_FIELD_C', 'Example Vardef', '<module>', 'varchar', 255, 0, 0, 0, 0, 0, 1, 'true');
一旦到位,进行维修和重建,您的新领域就可以使用了。
这将使该字段与 SugarBean 兼容:
$bean = BeanFactory::getBean('<module>');
$bean->new_field_c = 'abcd';
$bean->save();
将识别该字段并更新它。