如何在模块的子表中插入数据?例如,我有一个模块: mainmodule --它的表是主模块,模块的子表是mainmodule_sub。
所以我想知道如何使用mainmodule_sub将数据插入到SugarBean中。
为了更清楚地了解:
问题是大多数模块只有main_tables和_cstm表,而不是所有模块都有一两个表;所以我只想知道如何将数据插入到third_table中,比如说ProspectLists模块,它有这5个表,即prospect_lists、prospect_lists_cstm、prospect_lists_prospect、prospect_lists_campaign等等。
如何将数据插入prospect_lists_prospect?
发布于 2013-10-24 03:14:26
正如我从Stack向开发人员询问问题一样,到目前为止,您要么创建自己的API来完成它,要么通过SQL进行本地调用/插入,因为只有main_tables和_cstm表连接到每个ModuleAPI。
发布于 2013-10-22 10:16:10
我相信您的意思是存储通过Studio创建的自定义字段的表,默认情况下称为<module_name>_cstm。如果是这样的话,就需要调用$bean->custom_fields->retrieve();来访问。然后您可以使用普通的$bean->save();来存储它的值。
例如:
// Assume custom field 'account_custom_category_c'
$bean->custom_fields->retrieve();
$bean->account_custom_category_c = 'Very Big Company';
$bean->save();发布于 2019-02-18 12:49:16
您可以手动向_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数组中的模块名应该是单数的,例如“展望”,而不是“前景”):
<?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();将识别该字段并更新它。
https://stackoverflow.com/questions/19487229
复制相似问题