Creating new fields in a vtiger module

Recently, I got stuck with the help on how to create new fields in vtiger since vtiger has only a small community and its very difficult to find help online, I decided write a post so that someone else’s time can be saved. To add a field to an existing module, Follow the following steps:
  • Go to Settings>custom Fields>
  • Select the Module for which you want to create new fields
  • Click on Add New field option
  • Add Label name for the field
  • Select the Field Type
And you are done !!! In case your field is of the type picklist, then you would need to add the picklist values as well. Note that the above procedure will add the field to the current vtiger installation only. In case you want that the field to be budled with a vtiger installation, then you would need to do a bit of php. Fields in modules are controlled by the vtiger_field table – the field must exist in the appropriate database table, and there must be a record in vtiger_field that describes the field.
<pre>$this->db->query("insert into vtiger_field values ( <tabid>,
                                               $this->db->getUniqueID("vtiger_field"),
                                               <columnname>,
                                               <tablename>,
                                               <generatedtype>,
                                               <uitype>,
                                               <fieldname>,
                                               <fieldlabel>,
                                               <readonly>,
                                               <presence>,
                                               <selected>,
                                               <maximumlength>,
                                               <sequence>,
                                               <block>,
                                               <displaytype>,
                                               <typeofdata>,
                                               <quickcreate>,
                                               <quickcreatesequence>,
                                               <info_type>,
                                               <masseditable>,
                                               <helpinfo>
                                              )");
</pre>
Here is an overview of what each of the columns mean:
Field Description Allowed Values
tabid ID number of the module (from vtiger_tab) INT, tabid types
fieldid ID of field; generated by getUniqueID(“vtiger_field”). Normally obtained at installation. INT
columnname Name of the column in its table any
tablename Name of the table that stores field any table
generatedtype Specifies type of field in module whether 1=’Exisiting’ or 2=’User Defined’ 1,2
uitype Handles what widget displays field Ui types
fieldname The vTiger name of the field ??
fieldlabel The label name of the field vTiger will look for fieldlabel as a key in the the $mod_strings array stored at modules/ModuleName/language/<language prefix>.lang.php
readonly 0=true(ro) 1=false(rw) BOOLEAN
presence represent the field existence 1 to reprsent existence and 0 to represent non-existence
selected ?? ??
maximumlength ?? ??
sequence The display order of your field in your block. Number (1,2,3…)
block Block id (from Vtiger blocks) where the field will appear INT
displaytype Indicates if field will be displayed on Create/Edit & Detail View. 1=displayed on all views, 2=displayed only in detail view (but not in edit), 3=field will not come separately, it will come along with other field, 4= only in the createview. it will not come other views(detailview & editview) 1,2,3,4
typeofdata X~Y, where X is the type of data V for varchar, N for numbers etc and Y stands for (O)ptional or (M)andatory INV…~OM
quickcreate if field appears or not on quickcreate field 0/1
quickcreatesequence sequence of field in quick create screen number
info_type ‘BAS’ field is displayed in Basic Information, ‘ADV’ field is displayed in More information BAS or ADV
masseditable and helpinfo are the two new fields introduced in the latest version of vtiger(5.1.0 as i write the post). masseditable tells whether the field is masseditable or not. helpinfo lets you specify the helper text for the field(tooltip in this case). Right now(as of version 5.1.0), there is a problem with helpinfo field that it supports only one value and its not possible to localize the string. The following is an example query to add a new field called as website to a new module called as Vendors:

$this->db->query("insert into vtiger_field values (18,".$this->db->getUniqueID("vtiger_field").",'website','vtiger_vendor',1,'17',

'website','Website',1,2,0,100,6,45,'V~O',1,null,'BAS',1)");

You will need to add this query to modules/Users/DefaultDataPopulator.php to bundle the above field with a fresh vtiger installation. And thats all that you need to do to add a new field to a vtiger instance. Please let me know if any queries and we would be happy to answer.