[英]VTiger Extension Module create custom field for Accounts Module
我正在使用VTiger 6.4.0擴展模塊,該模塊用於在“帳戶”模塊中輸入公司名稱時獲取公司數據。
該模塊即將完成,我從API檢索數據,然后使用JQuery在輸入字段中輸入數據。
但是問題是我有一些與帳戶信息中現有字段無關的數據,因此我正在嘗試創建一些新的自定義字段。
只有我似乎無法弄清楚如何從我的擴展模塊中為“帳戶”模塊創建自定義字段。
我到處逛逛,看了一些關於stackoverflow的帖子。
我提出了下面的代碼部分,但這似乎不起作用。
public function addKvkfield(){
$module = new Vtiger_Module();
$module->name = 'Accounts';
$module = $module->getInstance('Accounts');
$blockInstance = new Vtiger_Block();
$blockInstance->label = 'LBL_ACCOUNT_INFORMATION';
$blockInstance = $blockInstance->getInstance($blockInstance->label,$module);
$fieldInstance = new Vtiger_Field();
$fieldInstance->name = 'KvKNummer';
$fieldInstance->table = $module->basetable;
$fieldInstance->column = 'kvknummer';
$fieldInstance->columntype = 'VARCHAR(100)';
$fieldInstance->uitype = 2;
$fieldInstance->typeofdata = 'V~M';
$blockInstance->addField($fieldInstance);
}
在vtlib_handler模塊中調用addKvkfield函數。postinstall(如果這是在擴展模塊中執行此操作的正確方法,則找不到任何信息)
vtlibhandler:
function vtlib_handler($modulename, $event_type) {
global $log;
if($event_type == 'module.postinstall') {
$this->addJSLinks();
$this->createConfigTable();
$this->addSettingsMenu();
$this->addKvkfield();
$this->updateLabels();
// TODO Handle post installation actions
} else if($event_type == 'module.disabled') {
// TODO Handle actions when this module is disabled.
} else if($event_type == 'module.enabled') {
// TODO Handle actions when this module is enabled.
} else if($event_type == 'module.preuninstall') {
// TODO Handle actions when this module is about to be deleted.
} else if($event_type == 'module.preupdate') {
// TODO Handle actions before this module is updated.
} else if($event_type == 'module.postupdate') {
$this->updateLabels();
// TODO Handle actions after this module is updated.
}
}
希望有人能給我正確的方向。
提前致謝 :)
我設法成功創建了帳戶模塊中需要的自定義字段。
感謝Vtiger郵件列表! :)
訣竅是對我編寫的代碼進行了少量改動:
public function addKvkfield(){
$module = Vtiger_Module::getInstance('Accounts');
$blockInstance = Vtiger_Block::getInstance('LBL_ACCOUNT_INFORMATION', $module);
$fieldInstance = new Vtiger_Field();
$fieldInstance->label = 'KvKNummer';
$fieldInstance->name = 'kvknummer';
$fieldInstance->column = $fieldInstance->name; // Good idea to keep name and columnname the same
$fieldInstance->columntype = 'VARCHAR(100)';
$fieldInstance->uitype = 1; // No need to use 2 anymore. Setting "M" below will introduce the Red asterisk
$fieldInstance->typeofdata = 'V~O';
$blockInstance->addField($fieldInstance);
}
上面的代碼將在“帳戶”模塊中創建一個(可選)自定義字段。
如果您在編寫新模塊並且從未安裝此模塊,則可以像我在問題中一樣在vtlib_handler中調用該函數。
但是在我的情況下,這是行不通的,因為在添加代碼以創建自定義字段之前,我已經安裝了插件。
所以我需要做的是在vtlib_handler module.postupdate上調用上面的函數(這將在模塊更新上添加自定義字段)
唯一的問題是,每當擴展程序更新時,它就會運行。
因此,我建議在函數中創建一個if語句,以檢查如果不運行腳本,該字段是否已存在於vtiger_field dbtable中。
希望我通過寫下來節省了別人一些時間:P
祝好運!
請參考以下鏈接在現有模塊中添加新字段
從“我的答案”中復制代碼,並使用ay名稱創建一個新的PHP文件。 將其放在CRM的根目錄中,然后運行到瀏覽器中。 您的字段將添加到模塊中。 您必須確保在復制的代碼中設置的參數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.