title: Vtiger custom module not saving
body: <p>I am creating a custom module in vtiger, this is the <code>Vehicles.php</code> file in the <code>Modules/Vehicles</code>:</p>
  
  <pre><code>&lt;?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' =&gt; 'crmid',
              'vtiger_vehicles' =&gt; 'vehiclesid',
              'vtiger_vehiclescf'=&gt;'vehiclesid');
  
      var $list_fields = Array (
              /* Format: Field Label =&gt; Array(tablename, columnname) */
              // tablename should not have prefix 'vtiger_'
              'Reg No' =&gt; Array('vehicles', 'reg_no'),
              'Assigned To' =&gt; Array('crmentity','smownerid')
      );
      var $list_fields_name = Array (
              /* Format: Field Label =&gt; fieldname */
              'Reg No' =&gt; 'reg_no',
              'Assigned To' =&gt; '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 =&gt; Array(tablename, columnname) */
              // tablename should not have prefix 'vtiger_'
              'Reg No' =&gt; Array('vehicles', 'reg_no'),
              'Assigned To' =&gt; Array('vtiger_crmentity','assigned_user_id'),
      );
      var $search_fields_name = Array (
              /* Format: Field Label =&gt; fieldname */
              'Reg No' =&gt; 'reg_no',
              'Assigned To' =&gt; '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.
      }
  }
  }
  </code></pre>
  
  <p>The file for creating the module is:</p>
  
  <pre><code>&lt;?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-&gt;delete();
  } else {
      $moduleInstance = new Vtiger_Module();
      $moduleInstance-&gt;name = $MODULENAME;
      $moduleInstance-&gt;parent= 'Inventory';
      $moduleInstance-&gt;save();
  
      // Schema Setup
      $moduleInstance-&gt;initTables();
  
      //Bring on the blocks
      $block = new Vtiger_Block();
      $block-&gt;label = 'LBL_'. strtoupper($moduleInstance-&gt;name) . '_INFORMATION';
      $table = "vtiger_".strtolower($moduleInstance-&gt;name);
      $moduleInstance-&gt;addBlock($block);
  
      $blockcf = new Vtiger_Block();
      $blockcf-&gt;label = 'LBL_CUSTOM_INFORMATION';
      $moduleInstance-&gt;addBlock($blockcf);
  
      $field1  = new Vtiger_Field();
      $field1-&gt;name = 'reg_no';
      $field1-&gt;label= 'Registration Number';
      $field1-&gt;uitype= 2;
      $field1-&gt;table = $table;
      $field1-&gt;column = $field1-&gt;name;
      $field1-&gt;columntype = 'VARCHAR(255)';
      $field1-&gt;typeofdata = 'V~M';
      $block-&gt;addField($field1);
      $moduleInstance-&gt;setEntityIdentifier($field1);
  
      $field2  = new Vtiger_Field();
      $field2-&gt;name = 'chas_no';
      $field2-&gt;label= 'Chassis Number';
      $field2-&gt;uitype= 2;
      $field2-&gt;column = $field1-&gt;name;
      $field2-&gt;columntype = 'VARCHAR(255)';
      $field2-&gt;typeofdata = 'V~O';
      $field2-&gt;table = $table;
      $block-&gt;addField($field2);
  
      $field3 = new Vtiger_Field();
      $field3-&gt;name= 'cust_name';
      $field3-&gt;label = 'Customer';
      $field3-&gt;uitype = 10;
      $field3-&gt;column = $field3-&gt;name;
      $field3-&gt;columntype ='VARCHAR(255)';
      $field3-&gt;typeofdata ='V~M';
      $field3-&gt;table = $table;
      $block-&gt;addField($field3);
      $field3-&gt;setRelatedModules(Array('Contacts'));
  
      // Recommended common fields every Entity module should have (linked to core table)
      $mfield1 = new Vtiger_Field();
      $mfield1-&gt;name = 'assigned_user_id';
      $mfield1-&gt;label = 'Assigned To';
      $mfield1-&gt;table = 'vtiger_crmentity';
      $mfield1-&gt;column = 'smownerid';
      $mfield1-&gt;uitype = 53;
      $mfield1-&gt;typeofdata = 'V~M';
      $block-&gt;addField($mfield1);
  
      $mfield2 = new Vtiger_Field();
      $mfield2-&gt;name = 'CreatedTime';
      $mfield2-&gt;label= 'Created Time';
      $mfield2-&gt;table = 'vtiger_crmentity';
      $mfield2-&gt;column = 'createdtime';
      $mfield2-&gt;uitype = 70;
      $mfield2-&gt;typeofdata = 'T~O';
      $mfield2-&gt;displaytype= 2;
      $block-&gt;addField($mfield2);
  
      $mfield3 = new Vtiger_Field();
      $mfield3-&gt;name = 'ModifiedTime';
      $mfield3-&gt;label= 'Modified Time';
      $mfield3-&gt;table = 'vtiger_crmentity';
      $mfield3-&gt;column = 'modifiedtime';
      $mfield3-&gt;uitype = 70;
      $mfield3-&gt;typeofdata = 'T~O';
      $mfield3-&gt;displaytype= 2;
      $block-&gt;addField($mfield3);
  
      // Filter Setup
      $filter1 = new Vtiger_Filter();
      $filter1-&gt;name = 'All';
      $filter1-&gt;isdefault = true;
      $moduleInstance-&gt;addFilter($filter1);
      $filter1-&gt;addField($field1)-&gt;addField($field2, 1)-&gt;addField($field3, 2)-&gt;addField($mfield1, 3);
  
      // Sharing Access Setup
      $moduleInstance-&gt;setDefaultSharing();
  
      // Webservice Setup
      $moduleInstance-&gt;initWebservice();
      }
  </code></pre>
  
  <p>Everything runs well:</p>
  
  <p>Creating Module Vehicles ... STARTED</p>
  
  <p>Initializing module permissions ... DONE</p>
  
  <p>Updating tabdata file ... DONE</p>
  
  <p>Setting up sharing access options ... DONE</p>
  
  <p>Added to menu Inventory ... DONE</p>
  
  <p>Updating parent_tabdata file ... STARTED</p>
  
  <p>Updating parent_tabdata file ... DONE</p>
  
  <p>Creating Module Vehicles ... DONE</p>
  
  <p>Creating Block LBL_VEHICLES_INFORMATION ... DONE</p>
  
  <p>Module language entry for LBL_VEHICLES_INFORMATION ... CHECK</p>
  
  <p>Creating Block LBL_CUSTOM_INFORMATION ... DONE</p>
  
  <p>Module language entry for LBL_CUSTOM_INFORMATION ... CHECK</p>
  
  <p>Creating Field reg_no ... DONE</p>
  
  <p>Module language mapping for Registration Number ... CHECK</p>
  
  <p>Setting entity identifier ... DONE</p>
  
  <p>Creating Field chas_no ... DONE</p>
  
  <p>Module language mapping for Chassis Number ... CHECK</p>
  
  <p>Creating Field cust_name ... DONE</p>
  
  <p>Module language mapping for Customer ... CHECK</p>
  
  <p>Setting cust_name relation with Contacts ... DONE</p>
  
  <p>Creating Field assigned_user_id ... DONE</p>
  
  <p>Module language mapping for Assigned To ... CHECK</p>
  
  <p>Creating Field CreatedTime ... DONE</p>
  
  <p>Module language mapping for Created Time ... CHECK</p>
  
  <p>Creating Field ModifiedTime ... DONE</p>
  
  <p>Module language mapping for Modified Time ... CHECK</p>
  
  <p>Creating Filter All ... DONE</p>
  
  <p>Setting Filter All to status [0] ... DONE</p>
  
  <p>Adding reg_no to All filter ... DONE</p>
  
  <p>Adding chas_no to All filter ... DONE</p>
  
  <p>Adding cust_name to All filter ... DONE</p>
  
  <p>Adding assigned_user_id to All filter ... DONE</p>
  
  <p>Recalculating sharing rules ... DONE</p>
  
  <p>Initializing webservices support ...DONE</p>
  
  <p>The module runs well but cannot add a record but shows this after saving:
  <img src="https://i.stack.imgur.com/gOYls.png" alt="On Save"></p>
  
  <p>What am I missing and how do I fix the error?</p>