phpmodulevtiger

Vtiger custom module not saving


I am creating a custom module in vtiger, this is the Vehicles.php file in the Modules/Vehicles:

<?php

include_once 'modules/Vtiger/CRMEntity.php';

class Vehicles extends Vtiger_CRMEntity {
    var $table_name = 'vtiger_vehicles';
    var $table_index= 'vehiclesid';

    var $customFieldTable = Array('vtiger_vehiclescf', 'vehiclesid');

    var $tab_name = Array('vtiger_crmentity', 'vtiger_vehicles', 'vtiger_vehiclescf');

    var $tab_name_index = Array(
            'vtiger_crmentity' => 'crmid',
            'vtiger_vehicles' => 'vehiclesid',
            'vtiger_vehiclescf'=>'vehiclesid');

    var $list_fields = Array (
            /* Format: Field Label => Array(tablename, columnname) */
            // tablename should not have prefix 'vtiger_'
            'Reg No' => Array('vehicles', 'reg_no'),
            'Assigned To' => Array('crmentity','smownerid')
    );
    var $list_fields_name = Array (
            /* Format: Field Label => fieldname */
            'Reg No' => 'reg_no',
            'Assigned To' => 'assigned_user_id',
    );

    // Make the field link to detail view
    var $list_link_field = 'reg_no';

    // For Popup listview and UI type support
    var $search_fields = Array(
            /* Format: Field Label => Array(tablename, columnname) */
            // tablename should not have prefix 'vtiger_'
            'Reg No' => Array('vehicles', 'reg_no'),
            'Assigned To' => Array('vtiger_crmentity','assigned_user_id'),
    );
    var $search_fields_name = Array (
            /* Format: Field Label => fieldname */
            'Reg No' => 'reg_no',
            'Assigned To' => 'assigned_user_id',
    );

    // For Popup window record selection
    var $popup_fields = Array ('reg_no');

    // For Alphabetical search
    var $def_basicsearch_col = 'reg_no';

    // Column value to use on detail view record text display
    var $def_detailview_recname = 'reg_no';

    // Used when enabling/disabling the mandatory fields for the module.
    // Refers to vtiger_field.fieldname values.
    var $mandatory_fields = Array('reg_no','assigned_user_id');

    var $default_order_by = 'reg_no';
    var $default_sort_order='ASC';
    /**
 * Invoked when special actions are performed on the module.
* @param String Module name
* @param String Event Type
*/
function vtlib_handler($moduleName, $eventType) {
    global $adb;
    if($eventType == 'module.postinstall') {
        // TODO Handle actions after this module is installed.
    } else if($eventType == 'module.disabled') {
        // TODO Handle actions before this module is being uninstalled.
    } else if($eventType == 'module.preuninstall') {
        // TODO Handle actions when this module is about to be deleted.
    } else if($eventType == 'module.preupdate') {
        // TODO Handle actions before this module is updated.
    } else if($eventType == 'module.postupdate') {
        // TODO Handle actions after this module is updated.
    }
}
}

The file for creating the module is:

<?php
include_once('vtlib/Vtiger/Module.php');

/**
*Init instance
*/
$Vtiger_Utils_Log = true;

$MODULENAME = 'Vehicles';

$moduleInstance = Vtiger_Module::getInstance($MODULENAME);
if ($moduleInstance || file_exists('modules/'.$MODULENAME)) {
    $moduleInstance->delete();
} else {
    $moduleInstance = new Vtiger_Module();
    $moduleInstance->name = $MODULENAME;
    $moduleInstance->parent= 'Inventory';
    $moduleInstance->save();

    // Schema Setup
    $moduleInstance->initTables();

    //Bring on the blocks
    $block = new Vtiger_Block();
    $block->label = 'LBL_'. strtoupper($moduleInstance->name) . '_INFORMATION';
    $table = "vtiger_".strtolower($moduleInstance->name);
    $moduleInstance->addBlock($block);

    $blockcf = new Vtiger_Block();
    $blockcf->label = 'LBL_CUSTOM_INFORMATION';
    $moduleInstance->addBlock($blockcf);

    $field1  = new Vtiger_Field();
    $field1->name = 'reg_no';
    $field1->label= 'Registration Number';
    $field1->uitype= 2;
    $field1->table = $table;
    $field1->column = $field1->name;
    $field1->columntype = 'VARCHAR(255)';
    $field1->typeofdata = 'V~M';
    $block->addField($field1);
    $moduleInstance->setEntityIdentifier($field1);

    $field2  = new Vtiger_Field();
    $field2->name = 'chas_no';
    $field2->label= 'Chassis Number';
    $field2->uitype= 2;
    $field2->column = $field1->name;
    $field2->columntype = 'VARCHAR(255)';
    $field2->typeofdata = 'V~O';
    $field2->table = $table;
    $block->addField($field2);

    $field3 = new Vtiger_Field();
    $field3->name= 'cust_name';
    $field3->label = 'Customer';
    $field3->uitype = 10;
    $field3->column = $field3->name;
    $field3->columntype ='VARCHAR(255)';
    $field3->typeofdata ='V~M';
    $field3->table = $table;
    $block->addField($field3);
    $field3->setRelatedModules(Array('Contacts'));

    // Recommended common fields every Entity module should have (linked to core table)
    $mfield1 = new Vtiger_Field();
    $mfield1->name = 'assigned_user_id';
    $mfield1->label = 'Assigned To';
    $mfield1->table = 'vtiger_crmentity';
    $mfield1->column = 'smownerid';
    $mfield1->uitype = 53;
    $mfield1->typeofdata = 'V~M';
    $block->addField($mfield1);

    $mfield2 = new Vtiger_Field();
    $mfield2->name = 'CreatedTime';
    $mfield2->label= 'Created Time';
    $mfield2->table = 'vtiger_crmentity';
    $mfield2->column = 'createdtime';
    $mfield2->uitype = 70;
    $mfield2->typeofdata = 'T~O';
    $mfield2->displaytype= 2;
    $block->addField($mfield2);

    $mfield3 = new Vtiger_Field();
    $mfield3->name = 'ModifiedTime';
    $mfield3->label= 'Modified Time';
    $mfield3->table = 'vtiger_crmentity';
    $mfield3->column = 'modifiedtime';
    $mfield3->uitype = 70;
    $mfield3->typeofdata = 'T~O';
    $mfield3->displaytype= 2;
    $block->addField($mfield3);

    // Filter Setup
    $filter1 = new Vtiger_Filter();
    $filter1->name = 'All';
    $filter1->isdefault = true;
    $moduleInstance->addFilter($filter1);
    $filter1->addField($field1)->addField($field2, 1)->addField($field3, 2)->addField($mfield1, 3);

    // Sharing Access Setup
    $moduleInstance->setDefaultSharing();

    // Webservice Setup
    $moduleInstance->initWebservice();
    }

Everything runs well:

Creating Module Vehicles ... STARTED

Initializing module permissions ... DONE

Updating tabdata file ... DONE

Setting up sharing access options ... DONE

Added to menu Inventory ... DONE

Updating parent_tabdata file ... STARTED

Updating parent_tabdata file ... DONE

Creating Module Vehicles ... DONE

Creating Block LBL_VEHICLES_INFORMATION ... DONE

Module language entry for LBL_VEHICLES_INFORMATION ... CHECK

Creating Block LBL_CUSTOM_INFORMATION ... DONE

Module language entry for LBL_CUSTOM_INFORMATION ... CHECK

Creating Field reg_no ... DONE

Module language mapping for Registration Number ... CHECK

Setting entity identifier ... DONE

Creating Field chas_no ... DONE

Module language mapping for Chassis Number ... CHECK

Creating Field cust_name ... DONE

Module language mapping for Customer ... CHECK

Setting cust_name relation with Contacts ... DONE

Creating Field assigned_user_id ... DONE

Module language mapping for Assigned To ... CHECK

Creating Field CreatedTime ... DONE

Module language mapping for Created Time ... CHECK

Creating Field ModifiedTime ... DONE

Module language mapping for Modified Time ... CHECK

Creating Filter All ... DONE

Setting Filter All to status [0] ... DONE

Adding reg_no to All filter ... DONE

Adding chas_no to All filter ... DONE

Adding cust_name to All filter ... DONE

Adding assigned_user_id to All filter ... DONE

Recalculating sharing rules ... DONE

Initializing webservices support ...DONE

The module runs well but cannot add a record but shows this after saving: On Save

What am I missing and how do I fix the error?


Solution

  • The mistake is in the line $field2->column = $field1->name;,

    It should be $field2->column = $field2->name;