[Vtigercrm-developers] Some columns are not created on new entity module

possebon possebon at gmail.com
Fri Jul 13 18:10:12 PDT 2012


Hi,

I'm trying to create a new entity module (from the book vtiger CRM
Beginner's Guide), for learning purpose, using the following script:

<?php
// Just a bit of HTML formatting
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//
EN" "http://www.w3.org/TR/html4/loose.dtd">';
echo '<html><head><title>vtlib Module Script</title>';
echo '<style type="text/css">@import url("themes/softed/style.css");br {
display: block; margin: 2px; }</style>';
echo '</head><body class=small style="font-size: 12px; margin: 2px;
padding: 2px;">';
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">';

// Start by turning on debugging and including necessary PHP files:
$Vtiger_Utils_Log = true;
include_once('vtlib/Vtiger/Menu.php');
include_once('vtlib/Vtiger/Module.php');

// Then create your module instance and save it. Finally, the call to
initWebservice() will initialize the webservice setup for our new module
instance:
$module = new Vtiger_Module();
$module->name = 'Location';
$module->save();
$module->initWebservice();
// Now initialize, or create, the tables required for your new module:
$module->initTables();

// Now add the module to the menu system.
// We're going to add it to the Sales dropdown menu in the main menu bar:
$menu = Vtiger_Menu::getInstance('Sales');
$menu->addModule($module);

// Now add a block for the basic module information:
$block1 = new Vtiger_Block();
$block1->label = 'LBL_LOCATION_INFORMATION';
$module->addBlock($block1);

// Now add a block for custom fields, so you can extend it in the future
through the user interface:
$block2 = new Vtiger_Block();
$block2->label = 'LBL_CUSTOM_INFORMATION';
$module->addBlock($block2);

// Now let's create the fields for the module. First we'll create the
Location Name field.
$field1->table = $module->basetable; // indicates that the field will
reside in the base table of your new custom module.
$field1->uitype = 2; // means a required text box. See here for more UI
types: http://wiki.vtiger.com/index.php/Ui_types
$field1->typeofdata = 'V~M'; // indicates that the field is Varchar and is
Mandatory. See here for more data types:
http://wiki.vtiger.com/index.php/INV...~ON
$field1 = new Vtiger_Field();
$field1->name = 'locationname';
$field1->label = 'Location Name';
$field1->table = $module->basetable;
$field1->column = 'locationname';
$field1->columntype = 'VARCHAR(255)';
$field1->uitype = 2;
$field1->typeofdata = 'V~M';
$block1->addField($field1);

// Set the name field as the field identifier:
$module->setEntityIdentifier($field1);

// Now add the Location Address field:
$field2 = new Vtiger_Field();
$field2->name = 'locationaddress';
$field2->label = 'Location Address';
$field2->table = $module->basetable;
$field2->column = 'locationaddress';
$field2->columntype = 'VARCHAR(255)';
$field2->uitype = 2;
$field2->typeofdata = 'V~O';// Varchar~Optional
$block1->addField($field2); // table and column are automatically set

// Now add the Location Address 2 field:
// Location address 2 field
$field3 = new Vtiger_Field();
$field3->name = 'locationaddress2';
$field3->label = 'Location Address 2';
$field3->table = $module->basetable;
$field3->column = 'locationaddress2';
$field3->columntype = 'VARCHAR(255)';
$field3->uitype = 2;
$field3->typeofdata = 'V~O'; // Date~Mandatory
$block1->addField($field3);

// Now add the Location City field:
$field4 = new Vtiger_Field();
$field4->name = 'locationcity';
$field4->label= 'Location City';
$field4->table = $module->basetable;
$field4->column = 'locationcity';
$field4->columntype = 'VARCHAR(255)';
$field4->uitype = 2;
$field4->typeofdata = 'V~O';

// Now add the Location State field:
$field5 = new Vtiger_Field();
$field5->name = 'locationstate';
$field5->label = 'Location State';
$field5->table = $module->basetable;
$field5->column = 'locationstate';
$field4->columntype = 'VARCHAR(255)';
$field5->uitype = 2;
$field5->typeofdata = 'V~O';
$block1->addField($field5);

// Add the Location Zip field:
$field6 = new Vtiger_Field();
$field6->name = 'locationzip';
$field6->label = 'Location Zip';
$field6->table = $module->basetable;
$field6->column = 'locationzip';
$field6->uitype = 2;
$field6->typeofdata = 'V~O';
$block1->addField($field6);

// Add common vTiger fields such as Assigned To, Created Time, and Modified
Time:
$field7 = new Vtiger_Field();
$field7->name = 'assigned_user_id';
$field7->label = 'Assigned To';
$field7->table = $module->basetable;
$field7->column = 'assigned_user_id';
$field7->table = 'vtiger_crmentity';
$field7->column = 'smownerid';
$field7->uitype = 53;
$field7->typeofdata = 'V~M';
$block1->addField($field7);
$field8 = new Vtiger_Field();
$field8->name = 'createdtime';
$field8->label= 'Created Time';
$field8->table = 'vtiger_crmentity';
$field8->column = 'createdtime';
$field8->uitype = 70;
$field8->typeofdata = 'T~O';
$field8->displaytype= 2;
$block1->addField($field8);
$field9 = new Vtiger_Field();
$field9->name = 'ModifiedTime';
$field9->label= 'Modified Time';
$field9->table = 'vtiger_crmentity';
$field9->column = 'modifiedtime';
$field9->uitype = 70;
$field9->typeofdata = 'T~O';
$field9->displaytype= 2;
$block1->addField($field9);

// Now let's add some related fields. vTiger uses related fields
// to show one-to-one relationships between entities as well as
// one-to-many and many-to-one, such as contacts and accounts.
// These fields will show in the basic information section,
// along with the previous fields. We'll add a related account field,
// so as to know which customer this location belongs to:

$field11 = new Vtiger_Field();
$field11->name = 'relatedaccount';
$field11->label= 'Related Account';
$field11->table = 'vtiger_location';
$field11->column = 'relatedaccount';
$field11->columntype = 'VARCHAR(100)';
$field11->uitype = 10;
$field11->typeofdata = 'V~O';
$field11->helpinfo = 'Relate to an existing account';
$block1->addField($field11);
$field11->setRelatedModules(Array('Accounts'));

// Now let's create a default filter, or view, for our module. It will just
show all records:
$filter1 = new Vtiger_Filter();
$filter1->name = 'All';
$filter1->isdefault = true;
$module->addFilter($filter1);

// Let's add some fields to the filter:
$filter1->addField($field1)->addField($field2,
1)->addField($field3, 2)->addField($field4, 3)->addField($field5,
4)->addField($field7, 5)->addField($field10,
6)->addField($field11, 7);

// Now, let's say we want to see a list of multiple contacts under the
// record for a single location. We can associate multiple records of
another module.
// Here's the code for associating multiple other contacts with this
location.
// You can see that the code gives the user the ability to either add a new
contact
// record while associating it with this location, or selecting a contact
that's already in vTiger:
$module->setRelatedList(Vtiger_Module::getInstance('Contacts'),
'Contacts', Array('ADD','SELECT'));

// Now, set the sharing access for the Locations module to Private.
// You'll be able to change it later in the Settings section:
$module->setDefaultSharing('Private');

// Now, let's enable the Import/Export tool, but disable merging:
$module->enableTools(Array('Import', 'Export'));
$module->disableTools('Merge');

// Finally, let's enable this module for use with web services:
$moduleInstance = Vtiger_Module::getInstance('Location');
$moduleInstance->initWebservice();

// Close up the PHP file with some HTML:
echo '</body></html>';
?>

The response when executing the script is:

Creating Module Location ... STARTED
Initializing module permissions ... DONE
Updating tabdata file ... DONE
Setting up sharing access options ... DONE
Creating Module Location ... DONE
Initializing webservices support ...DONE
Added to menu Sales ... DONE
Updating parent_tabdata file ... STARTED
Updating parent_tabdata file ... DONE
Creating Block LBL_LOCATION_INFORMATION ... DONE
Module language entry for LBL_LOCATION_INFORMATION ... CHECK
Creating Block LBL_CUSTOM_INFORMATION ... DONE
Module language entry for LBL_CUSTOM_INFORMATION ... CHECK
Creating Field locationname ... DONE
Module language mapping for Location Name ... CHECK
Setting entity identifier ... DONE
Creating Field locationaddress ... DONE
Module language mapping for Location Address ... CHECK
Creating Field locationaddress2 ... DONE
Module language mapping for Location Address 2 ... CHECK
Creating Field locationstate ... DONE
Module language mapping for Location State ... CHECK
Creating Field locationzip ... DONE
Module language mapping for Location Zip ... CHECK
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 Field relatedaccount ... DONE
Module language mapping for Related Account ... CHECK
Setting relatedaccount relation with Accounts ... DONE
Creating Filter All ... DONE
Setting Filter All to status [0] ... DONE
Adding locationname to All filter ... DONE
Adding locationaddress to All filter ... DONE
Adding locationaddress2 to All filter ... DONE
Adding locationcity to All filter ... DONE
Adding locationstate to All filter ... DONE
Adding assigned_user_id to All filter ... DONE

The module will run Ok, but when I try to save a record, I have the
following error message:

Record you are trying to access is not found. Go Back.


Looking at vtigercrm.log I found this:

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 = vtiger_users.id 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'


Checking on vtiger_location table:


mysql> desc vtiger_location;
+------------------+--------------+------+-----+---------+-------+
| Field            | Type         | Null | Key | Default | Extra |
+------------------+--------------+------+-----+---------+-------+
| locationid       | int(11)      | YES  |     | NULL    |       |
| locationname     | varchar(255) | YES  |     | NULL    |       |
| locationaddress  | varchar(255) | YES  |     | NULL    |       |
| locationaddress2 | varchar(255) | YES  |     | NULL    |       |
| relatedaccount   | varchar(100) | YES  |     | NULL    |       |
+------------------+--------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

I discovered that the following columns were not created:

locationcity
locationstate
locationzip

I checked on vtiger_fields table and all fields appears there:

mysql> select
 tabid,fieldid,columnname,tablename,generatedtype,uitype,fieldname,typeofdata
 from vtiger_field where tabid=78;
+-------+---------+------------------+------------------+---------------+--------+------------------+------------+
| tabid | fieldid | columnname       | tablename        | generatedtype |
uitype | fieldname        | typeofdata |
+-------+---------+------------------+------------------+---------------+--------+------------------+------------+
|    78 |     980 | locationname     | vtiger_location  |             1 | 2
     | locationname     | V~M        |
|    78 |     981 | locationaddress  | vtiger_location  |             1 | 2
     | locationaddress  | V~O        |
|    78 |     982 | locationaddress2 | vtiger_location  |             1 | 2
     | locationaddress2 | V~O        |
|    78 |     983 | locationstate    | vtiger_location  |             1 | 2
     | locationstate    | V~O        |
|    78 |     984 | locationzip      | vtiger_location  |             1 | 2
     | locationzip      | V~O        |
|    78 |     985 | smownerid        | vtiger_crmentity |             1 |
53     | assigned_user_id | V~M        |
|    78 |     986 | createdtime      | vtiger_crmentity |             1 |
70     | createdtime      | T~O        |
|    78 |     987 | modifiedtime     | vtiger_crmentity |             1 |
70     | ModifiedTime     | T~O        |
|    78 |     988 | relatedaccount   | vtiger_location  |             1 |
10     | relatedaccount   | V~O        |
+-------+---------+------------------+------------------+---------------+--------+------------------+------------+
9 rows in set (0.00 sec)


I could not find any errors. With someone could give some help, will be
very appreciated.

Thanks in advance,

Fernando Possebon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20120713/fbcd0b74/attachment-0001.html 


More information about the vtigercrm-developers mailing list