【问题标题】:VTiger Extension Module create custom field for Accounts ModuleVTiger 扩展模块为帐户模块创建自定义字段
【发布时间】:2016-02-27 14:59:41
【问题描述】:

我正在开发一个 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 module.postinstall 中调用 addKvkfield 函数(如果这是在扩展模块中执行此操作的正确方法,则找不到任何信息)

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.
    }
}

希望有人可以推动我朝着正确的方向前进。

提前致谢:)

【问题讨论】:

    标签: custom-fields vtiger extension-modules


    【解决方案1】:

    我成功地在账户模块中创建了我需要的自定义字段。

    感谢 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);
    
    }
    

    以上代码将在 Account 模块中创建一个(可选的)自定义字段。

    如果您编写了一个新模块并且从未安装过该模块,那么您可以像我在问题中所做的那样调用 vtlib_handler 中的函数。

    但就我而言,这不起作用,因为我在添加代码以创建自定义字段之前已经安装了插件。

    所以我需要做的是在 vtlib_handler module.postupdate 上调用上面的函数(这将在模块更新时添加自定义字段)

    唯一的问题是每次更新扩展时它都会运行。

    所以我建议在函数中创建一个 if 语句来检查该字段是否已经存在于 vtiger_field dbtable 中,如果不运行脚本。

    希望我把这一切写下来为别人节省了一些时间:P

    祝你好运!

    【讨论】:

      【解决方案2】:

      请参考以下链接 Add New Field in existing Module

      从 My Answer 中复制代码并创建一个名称为 ay 的新 PHP 文件。将其放在 CRM 的根目录中并运行到浏览器中。您的字段将被添加到您的模块中。您必须确保您在复制的代码中设置的参数。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-08-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多