Hi,<div><br></div><div>I'm trying to create a new entity module (from the book vtiger CRM Beginner's Guide), for learning purpose, using the following script:</div><div><br></div><div><div><?php</div><div>// Just a bit of HTML formatting</div>
<div>echo '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//</div><div>EN" "<a href="http://www.w3.org/TR/html4/loose.dtd">http://www.w3.org/TR/html4/loose.dtd</a>">';</div><div>
echo '<html><head><title>vtlib Module Script</title>';</div><div>echo '<style type="text/css">@import url("themes/softed/style.css");br { display: block; margin: 2px; }</style>';</div>
<div>echo '</head><body class=small style="font-size: 12px; margin: 2px; padding: 2px;">';</div><div>echo '<a href="index.php"><img src="themes/softed/images/vtiger-crm.gif" alt="vtiger CRM" title="vtiger CRM" border=0></a><hr style="height: 1px">';</div>
<div><br></div><div>// Start by turning on debugging and including necessary PHP files:</div><div>$Vtiger_Utils_Log = true;</div><div>include_once('vtlib/Vtiger/Menu.php');</div><div>include_once('vtlib/Vtiger/Module.php');</div>
<div><br></div><div>// Then create your module instance and save it. Finally, the call to initWebservice() will initialize the webservice setup for our new module instance:</div><div>$module = new Vtiger_Module();</div><div>
$module->name = 'Location';</div><div>$module->save();</div><div>$module->initWebservice();</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div>// Now initialize, or create, the tables required for your new module:</div>
<div>$module->initTables();</div><div><br></div><div>// Now add the module to the menu system. </div><div>// We're going to add it to the Sales dropdown menu in the main menu bar:</div><div>$menu = Vtiger_Menu::getInstance('Sales');</div>
<div>$menu->addModule($module);</div><div><br></div><div>// Now add a block for the basic module information:</div><div>$block1 = new Vtiger_Block();</div><div>$block1->label = 'LBL_LOCATION_INFORMATION';</div>
<div>$module->addBlock($block1);</div><div><br></div><div>// Now add a block for custom fields, so you can extend it in the future through the user interface:</div><div>$block2 = new Vtiger_Block();</div><div>$block2->label = 'LBL_CUSTOM_INFORMATION';</div>
<div>$module->addBlock($block2);</div><div><br></div><div>// Now let's create the fields for the module. First we'll create the Location Name field.</div><div>$field1->table = $module->basetable; // indicates that the field will reside in the base table of your new custom module.</div>
<div>$field1->uitype = 2; // means a required text box. See here for more UI types: <a href="http://wiki.vtiger.com/index.php/Ui_types">http://wiki.vtiger.com/index.php/Ui_types</a></div><div>$field1->typeofdata = 'V~M'; // indicates that the field is Varchar and is Mandatory. See here for more data types: <a href="http://wiki.vtiger.com/index.php/INV...~ON">http://wiki.vtiger.com/index.php/INV...~ON</a></div>
<div>$field1 = new Vtiger_Field();</div><div>$field1->name = 'locationname';</div><div>$field1->label = 'Location Name';</div><div>$field1->table = $module->basetable;</div><div>$field1->column = 'locationname';</div>
<div>$field1->columntype = 'VARCHAR(255)';</div><div>$field1->uitype = 2;</div><div>$field1->typeofdata = 'V~M';</div><div>$block1->addField($field1);</div><div><br></div><div>// Set the name field as the field identifier:</div>
<div>$module->setEntityIdentifier($field1);</div><div><br></div><div>// Now add the Location Address field:</div><div>$field2 = new Vtiger_Field();</div><div>$field2->name = 'locationaddress';</div><div>$field2->label = 'Location Address';</div>
<div>$field2->table = $module->basetable;</div><div>$field2->column = 'locationaddress';</div><div>$field2->columntype = 'VARCHAR(255)';</div><div>$field2->uitype = 2;</div><div>$field2->typeofdata = 'V~O';// Varchar~Optional</div>
<div>$block1->addField($field2); // table and column are automatically set</div><div><br></div><div>// Now add the Location Address 2 field:</div><div>// Location address 2 field</div><div>$field3 = new Vtiger_Field();</div>
<div>$field3->name = 'locationaddress2';</div><div>$field3->label = 'Location Address 2';</div><div>$field3->table = $module->basetable;</div><div>$field3->column = 'locationaddress2';</div>
<div>$field3->columntype = 'VARCHAR(255)';</div><div>$field3->uitype = 2;</div><div>$field3->typeofdata = 'V~O'; // Date~Mandatory</div><div>$block1->addField($field3);</div><div><br></div><div>
// Now add the Location City field:</div><div>$field4 = new Vtiger_Field();</div><div>$field4->name = 'locationcity';</div><div>$field4->label= 'Location City';</div><div>$field4->table = $module->basetable;</div>
<div>$field4->column = 'locationcity';</div><div>$field4->columntype = 'VARCHAR(255)';</div><div>$field4->uitype = 2;</div><div>$field4->typeofdata = 'V~O';</div><div><br></div><div>// Now add the Location State field:</div>
<div>$field5 = new Vtiger_Field();</div><div>$field5->name = 'locationstate';</div><div>$field5->label = 'Location State';</div><div>$field5->table = $module->basetable;</div><div>$field5->column = 'locationstate';</div>
<div>$field4->columntype = 'VARCHAR(255)';</div><div>$field5->uitype = 2;</div><div>$field5->typeofdata = 'V~O';</div><div>$block1->addField($field5);</div><div><br></div><div>// Add the Location Zip field:</div>
<div>$field6 = new Vtiger_Field();</div><div>$field6->name = 'locationzip';</div><div>$field6->label = 'Location Zip';</div><div>$field6->table = $module->basetable;</div><div>$field6->column = 'locationzip';</div>
<div>$field6->uitype = 2;</div><div>$field6->typeofdata = 'V~O';</div><div>$block1->addField($field6);</div><div><br></div><div>// Add common vTiger fields such as Assigned To, Created Time, and Modified Time:</div>
<div>$field7 = new Vtiger_Field();</div><div>$field7->name = 'assigned_user_id';</div><div>$field7->label = 'Assigned To';</div><div>$field7->table = $module->basetable;</div><div>$field7->column = 'assigned_user_id';</div>
<div>$field7->table = 'vtiger_crmentity';</div><div>$field7->column = 'smownerid';</div><div>$field7->uitype = 53;</div><div>$field7->typeofdata = 'V~M';</div><div>$block1->addField($field7);</div>
<div>$field8 = new Vtiger_Field();</div><div>$field8->name = 'createdtime';</div><div>$field8->label= 'Created Time';</div><div>$field8->table = 'vtiger_crmentity';</div><div>$field8->column = 'createdtime';</div>
<div>$field8->uitype = 70;</div><div>$field8->typeofdata = 'T~O';</div><div>$field8->displaytype= 2;</div><div>$block1->addField($field8);</div><div>$field9 = new Vtiger_Field();</div><div>$field9->name = 'ModifiedTime';</div>
<div>$field9->label= 'Modified Time';</div><div>$field9->table = 'vtiger_crmentity';</div><div>$field9->column = 'modifiedtime';</div><div>$field9->uitype = 70;</div><div>$field9->typeofdata = 'T~O';</div>
<div>$field9->displaytype= 2;</div><div>$block1->addField($field9);</div><div><br></div><div>// Now let's add some related fields. vTiger uses related fields</div><div>// to show one-to-one relationships between entities as well as</div>
<div>// one-to-many and many-to-one, such as contacts and accounts.</div><div>// These fields will show in the basic information section, </div><div>// along with the previous fields. We'll add a related account field, </div>
<div>// so as to know which customer this location belongs to:</div><div><br></div><div>$field11 = new Vtiger_Field();</div><div>$field11->name = 'relatedaccount';</div><div>$field11->label= 'Related Account';</div>
<div>$field11->table = 'vtiger_location';</div><div>$field11->column = 'relatedaccount';</div><div>$field11->columntype = 'VARCHAR(100)';</div><div>$field11->uitype = 10;</div><div>$field11->typeofdata = 'V~O';</div>
<div>$field11->helpinfo = 'Relate to an existing account';</div><div>$block1->addField($field11);</div><div>$field11->setRelatedModules(Array('Accounts'));</div><div><br></div><div>// Now let's create a default filter, or view, for our module. It will just show all records:</div>
<div>$filter1 = new Vtiger_Filter();</div><div>$filter1->name = 'All';</div><div>$filter1->isdefault = true;</div><div>$module->addFilter($filter1);</div><div><br></div><div>// Let's add some fields to the filter:</div>
<div>$filter1->addField($field1)->addField($field2,</div><div>1)->addField($field3, 2)->addField($field4, 3)->addField($field5,</div><div>4)->addField($field7, 5)->addField($field10,</div><div>6)->addField($field11, 7);</div>
<div><br></div><div>// Now, let's say we want to see a list of multiple contacts under the </div><div>// record for a single location. We can associate multiple records of another module. </div><div>// Here's the code for associating multiple other contacts with this location. </div>
<div>// You can see that the code gives the user the ability to either add a new contact </div><div>// record while associating it with this location, or selecting a contact that's already in vTiger:</div><div>$module->setRelatedList(Vtiger_Module::getInstance('Contacts'),</div>
<div>'Contacts', Array('ADD','SELECT'));</div><div><br></div><div>// Now, set the sharing access for the Locations module to Private. </div><div>// You'll be able to change it later in the Settings section:</div>
<div>$module->setDefaultSharing('Private');</div><div><br></div><div>// Now, let's enable the Import/Export tool, but disable merging:</div><div>$module->enableTools(Array('Import', 'Export'));</div>
<div>$module->disableTools('Merge');</div><div><br></div><div>// Finally, let's enable this module for use with web services:</div><div>$moduleInstance = Vtiger_Module::getInstance('Location');</div>
<div>$moduleInstance->initWebservice();</div><div><br></div><div>// Close up the PHP file with some HTML:</div><div>echo '</body></html>';</div><div>?></div><div><br></div></div><div>The response when executing the script is:</div>
<div><br></div><div><span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Creating Module Location ... STARTED</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px">
<span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Initializing module permissions ... DONE</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px"><span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Updating tabdata file ... DONE</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px">
<span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Setting up sharing access options ... DONE</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px"><span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Creating Module Location ... DONE</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px">
<span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Initializing webservices support ...DONE</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px"><span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Added to menu Sales ... DONE</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px">
<span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Updating parent_tabdata file ... STARTED</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px"><span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Updating parent_tabdata file ... DONE</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px">
<span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Creating Block LBL_LOCATION_INFORMATION ... DONE</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px"><span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Module language entry for LBL_LOCATION_INFORMATION ... CHECK</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px">
<span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Creating Block LBL_CUSTOM_INFORMATION ... DONE</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px"><span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Module language entry for LBL_CUSTOM_INFORMATION ... CHECK</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px">
<span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Creating Field locationname ... DONE</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px"><span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Module language mapping for Location Name ... CHECK</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px">
<span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Setting entity identifier ... DONE</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px"><span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Creating Field locationaddress ... DONE</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px">
<span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Module language mapping for Location Address ... CHECK</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px">
<span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Creating Field locationaddress2 ... DONE</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px">
<span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Module language mapping for Location Address 2 ... CHECK</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px">
<span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Creating Field locationstate ... DONE</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px"><span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Module language mapping for Location State ... CHECK</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px">
<span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Creating Field locationzip ... DONE</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px"><span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Module language mapping for Location Zip ... CHECK</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px">
<span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Creating Field assigned_user_id ... DONE</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px"><span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Module language mapping for Assigned To ... CHECK</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px">
<span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Creating Field createdtime ... DONE</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px"><span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Module language mapping for Created Time ... CHECK</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px">
<span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Creating Field ModifiedTime ... DONE</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px"><span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Module language mapping for Modified Time ... CHECK</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px">
<span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Creating Field relatedaccount ... DONE</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px"><span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Module language mapping for Related Account ... CHECK</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px">
<span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Setting relatedaccount relation with Accounts ... DONE</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px">
<span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Creating Filter All ... DONE</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px">
<span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Setting Filter All to status [0] ... DONE</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px"><span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Adding locationname to All filter ... DONE</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px">
<span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Adding locationaddress to All filter ... DONE</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px"><span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Adding locationaddress2 to All filter ... DONE</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px">
<span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Adding locationcity to All filter ... DONE</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px"><span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Adding locationstate to All filter ... DONE</span><br style="display:block;margin:2px;font-family:Arial,Helvetica,sans-serif;font-size:12px">
<span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">Adding assigned_user_id to All filter ... DONE</span>
</div><div><span style="font-family:Arial,Helvetica,sans-serif;font-size:12px"><br></span></div><div><span style="font-family:Arial,Helvetica,sans-serif;font-size:12px">The module will run Ok, but when I try to save a record, I have the following error message:</span></div>
<div><span style="font-family:Arial,Helvetica,sans-serif;font-size:12px"><br></span></div>Record you are trying to access is not found. Go Back.<div><br></div><div><br></div><div>Looking at vtigercrm.log I found this:</div>
<div><br></div><div><div>Sat Jul 14 00:15:00 2012,224 [30517] INFO VT - PearDatabase ->ADODB error Query Failed:SELECT vtiger_location.locationname, vtiger_location.locationaddress, vtiger_location.locationaddress2, vtiger_location.locationstate, vtiger_crmentity.smownerid, vtiger_location.locationid FROM vtiger_location INNER JOIN vtiger_crmentity ON vtiger_location.locationid = vtiger_crmentity.crmid LEFT JOIN vtiger_users ON vtiger_crmentity.smownerid = <a href="http://vtiger_users.id">vtiger_users.id</a> LEFT JOIN vtiger_groups ON vtiger_crmentity.smownerid = vtiger_groups.groupid WHERE vtiger_crmentity.deleted=0 AND vtiger_location.locationid > 0 LIMIT 0, 20::->[1054]Unknown column 'vtiger_location.locationstate' in 'field list'</div>
</div><div><br></div><div><br></div><div>Checking on vtiger_location table:</div><div><br></div><div><div><br></div><div>mysql> desc vtiger_location;</div><div>+------------------+--------------+------+-----+---------+-------+</div>
<div>| Field | Type | Null | Key | Default | Extra |</div><div>+------------------+--------------+------+-----+---------+-------+</div><div>| locationid | int(11) | YES | | NULL | |</div>
<div>| locationname | varchar(255) | YES | | NULL | |</div><div>| locationaddress | varchar(255) | YES | | NULL | |</div><div>| locationaddress2 | varchar(255) | YES | | NULL | |</div>
<div>| relatedaccount | varchar(100) | YES | | NULL | |</div><div>+------------------+--------------+------+-----+---------+-------+</div><div>5 rows in set (0.00 sec)</div></div><div><br></div><div>I discovered that the following columns were not created:</div>
<div><br></div><div>locationcity</div><div>locationstate</div><div>locationzip</div><div><br></div><div>I checked on vtiger_fields table and all fields appears there:</div><div><br></div><div><div>mysql> select tabid,fieldid,columnname,tablename,generatedtype,uitype,fieldname,typeofdata from vtiger_field where tabid=78;</div>
<div>+-------+---------+------------------+------------------+---------------+--------+------------------+------------+</div><div>| tabid | fieldid | columnname | tablename | generatedtype | uitype | fieldname | typeofdata |</div>
<div>+-------+---------+------------------+------------------+---------------+--------+------------------+------------+</div><div>| 78 | 980 | locationname | vtiger_location | 1 | 2 | locationname | V~M |</div>
<div>| 78 | 981 | locationaddress | vtiger_location | 1 | 2 | locationaddress | V~O |</div><div>| 78 | 982 | locationaddress2 | vtiger_location | 1 | 2 | locationaddress2 | V~O |</div>
<div>| 78 | 983 | locationstate | vtiger_location | 1 | 2 | locationstate | V~O |</div><div>| 78 | 984 | locationzip | vtiger_location | 1 | 2 | locationzip | V~O |</div>
<div>| 78 | 985 | smownerid | vtiger_crmentity | 1 | 53 | assigned_user_id | V~M |</div><div>| 78 | 986 | createdtime | vtiger_crmentity | 1 | 70 | createdtime | T~O |</div>
<div>| 78 | 987 | modifiedtime | vtiger_crmentity | 1 | 70 | ModifiedTime | T~O |</div><div>| 78 | 988 | relatedaccount | vtiger_location | 1 | 10 | relatedaccount | V~O |</div>
<div>+-------+---------+------------------+------------------+---------------+--------+------------------+------------+</div><div>9 rows in set (0.00 sec)</div></div><div><br></div><div><br></div><div>I could not find any errors. With someone could give some help, will be very appreciated.</div>
<div><br></div><div>Thanks in advance,</div><div><br></div><div>Fernando Possebon</div><div><br></div><div><br><div><br></div></div>