{"id":2015,"date":"2024-07-25T03:57:01","date_gmt":"2024-07-25T03:57:01","guid":{"rendered":"https:\/\/itnotes.apjsoftwares.in\/?p=2015"},"modified":"2024-07-28T05:48:09","modified_gmt":"2024-07-28T05:48:09","slug":"how-to-create-new-module-in-vtiger-crm","status":"publish","type":"post","link":"https:\/\/itnotes.apjsoftwares.in\/index.php\/2024\/07\/25\/how-to-create-new-module-in-vtiger-crm\/","title":{"rendered":"How to create new module in vtiger CRM?"},"content":{"rendered":"\n<p><strong>Creating a new Entity Module<\/strong><\/p>\n\n\n\n<p>vtlib simplifies the creation of new CRM modules. Developers can use the vtlib to develop vtiger<br>CRM modules that add new functionality to the vtiger CRM. These modules can then be packaged for<br>easy installation by the Module Manager.<\/p>\n\n\n\n<p>The following are important steps that should be followed to get a basic working module. The<br>backend section covers database-level changes for the module, and the frontend section covers<br>the UI files.<\/p>\n\n\n\n<p><strong>Backend<\/strong><\/p>\n\n\n\n<ul>\n<li>Step 1 Create module instance, create database tables, and add it to Menu<\/li>\n\n\n\n<li>Step 2 Add UI blocks for the module.<\/li>\n\n\n\n<li>Step 3 Add fields and associate them to blocks. Set at least one field as an entity identifier.<\/li>\n\n\n\n<li>Step 4 Create default list view and additional filters (make sure to create a filter named All which is<\/li>\n\n\n\n<li>the default filter)<\/li>\n\n\n\n<li>Step 5 Create Related List (to show in the &#8221;More information&#8221; tab)<\/li>\n\n\n\n<li>Step 6 Setting Sharing Access Rules<\/li>\n\n\n\n<li>Step 7 Setting Module Tools options (i.e., Import\/Export)<\/li>\n<\/ul>\n\n\n\n<p><strong>FrontEnd<\/strong><br>    Step 8 Creating Module directory and files<\/p>\n\n\n\n<p><strong>Packaging<\/strong><br>    Step 9 Packaging<\/p>\n\n\n\n<p><strong>Additional Options<\/strong><br>\u2794 Module Templates (to customize Form, List View, and Settings UI )<br>\u2794 Module Settings (to allow administrators to configure your module)<br>\u2794 Module Events (only available in vtiger CRM version 5.1)<br>\u2794 Module Webservices (only available in vtiger CRM version 5.1)<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Creating Payslip Module in Vtiger<\/strong><\/p>\n\n\n\n<p>It will have the ability to create, edit, and delete payslip records. You can create Custom Filters for the Listview,<br>which displays the list of payslip instances.<\/p>\n\n\n\n<p><strong>Step 1: Creating Module<\/strong><\/p>\n\n\n\n<p>Class Vtiger_Module provides an API to work with Vtiger CRM modules.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>include_once('vtlib\/Vtiger\/Module.php'); \n$moduleInstance = new Vtiger_Module(); \n$moduleInstance-&gt;name = 'Payslip'; \n$moduleInstance-&gt;save(); \n$moduleInstance-&gt;initTables(); \n$menuInstance = Vtiger_Menu::getInstance('Tools'); \n$menuInstance-&gt;addModule($moduleInstance);<\/code><\/pre>\n\n\n\n<p>Vtiger_Module-&gt;initTables() API will initialize (create) the 3 necessary tables a module should<br>have as explained below:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"154\" src=\"https:\/\/itnotes.apjsoftwares.in\/wp-content\/uploads\/2024\/07\/image-1024x154.png\" alt=\"\" class=\"wp-image-2020\" srcset=\"https:\/\/itnotes.apjsoftwares.in\/wp-content\/uploads\/2024\/07\/image-1024x154.png 1024w, https:\/\/itnotes.apjsoftwares.in\/wp-content\/uploads\/2024\/07\/image-300x45.png 300w, https:\/\/itnotes.apjsoftwares.in\/wp-content\/uploads\/2024\/07\/image-768x115.png 768w, https:\/\/itnotes.apjsoftwares.in\/wp-content\/uploads\/2024\/07\/image.png 1472w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Vtiger_Menu-&gt;addModule() API will create a menu item which serves as a UI entry point for the module.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Step 2: Creating Block (in UI Form)<\/strong><br>Class Vtiger_Block provides API to work with a Module block, the container which holds the fields<br>together.<br>The example given below describes the way of creating new blocks for the module created earlier:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>include_once('vtlib\/Vtiger\/Module.php');\n$blockInstance = new Vtiger_Block();\n$blockInstance-&gt;label = 'LBL_PAYSLIP_INFORMATION';\n$moduleInstance-&gt;addBlock($blockInstance);\n$blockInstance2 = new Vtiger_Block();\n$blockInstance2-&gt;label = 'LBL_CUSTOM_INFORMATION';\n$moduleInstance-&gt;addBlock($blockInstance2);<\/code><\/pre>\n\n\n\n<p>NOTE: LBL_CUSTOM_INFORMATION block should always be created to support Custom Fields for a module<\/p>\n\n\n\n<p><strong>Step 3: Adding Fields<\/strong><br>Class Vtiger_Field provides API to work with a Module field, which are the basic elements that store and display the module record data. The example given below describes the way of creating a new field for the module created earlier:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>include_once('vtlib\/Vtiger\/Module.php');\n$fieldInstance = new Vtiger_Field();\n$fieldInstance-&gt;name = 'PayslipName';\n$fieldInstance-&gt;table = 'vtiger_payslip';\n$fieldInstance-&gt;column = 'payslipname';\n$fieldInstance-&gt;columntype = 'VARCHAR(100)';\n$fieldInstance-&gt;uitype = 2;\n$fieldInstance-&gt;typeofdata = 'V~M';\n$blockInstance-&gt;addField($fieldInstance);<\/code><\/pre>\n\n\n\n<p>NOTE: The fieldInstance name is a mandatory value to be set before saving\/adding to the block.<br>Other values (if not set) are defaulted as explained below:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"251\" src=\"https:\/\/itnotes.apjsoftwares.in\/wp-content\/uploads\/2024\/07\/image-1-1024x251.png\" alt=\"\" class=\"wp-image-2026\" srcset=\"https:\/\/itnotes.apjsoftwares.in\/wp-content\/uploads\/2024\/07\/image-1-1024x251.png 1024w, https:\/\/itnotes.apjsoftwares.in\/wp-content\/uploads\/2024\/07\/image-1-300x74.png 300w, https:\/\/itnotes.apjsoftwares.in\/wp-content\/uploads\/2024\/07\/image-1-768x189.png 768w, https:\/\/itnotes.apjsoftwares.in\/wp-content\/uploads\/2024\/07\/image-1.png 1466w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"284\" src=\"https:\/\/itnotes.apjsoftwares.in\/wp-content\/uploads\/2024\/07\/image-2-1024x284.png\" alt=\"\" class=\"wp-image-2029\" srcset=\"https:\/\/itnotes.apjsoftwares.in\/wp-content\/uploads\/2024\/07\/image-2-1024x284.png 1024w, https:\/\/itnotes.apjsoftwares.in\/wp-content\/uploads\/2024\/07\/image-2-300x83.png 300w, https:\/\/itnotes.apjsoftwares.in\/wp-content\/uploads\/2024\/07\/image-2-768x213.png 768w, https:\/\/itnotes.apjsoftwares.in\/wp-content\/uploads\/2024\/07\/image-2.png 1461w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><strong>Entity Identifier<\/strong><br>One mandatory field should be set as entity identifier of module once it is created. This field will be used for showing the details in &#8216;Last Viewed Entries&#8217; etc\u2026<\/p>\n\n\n\n<p>$moduleInstance-&gt;setEntityIdentifier($fieldInstance);<\/p>\n\n\n\n<p><strong>Set Picklist Values<\/strong><\/p>\n\n\n\n<p>If the field is of Picklist type (UI type 15, 16, 33, 55, 111) then you can configure the initial values using the following API:<br>$fieldInstance-&gt;setPicklistValues( Array (&#8216;Value1&#8217;, &#8216;Value2&#8217;) );<\/p>\n\n\n\n<p><strong>Set Related Module<\/strong><\/p>\n\n\n\n<p>If the field is of Popup select type (uitype=10), you can configure the related modules which could be selected via Popup using the following API:<br>$fieldInstance-&gt;setRelatedModules(Array(&#8216;OtherModule1&#8217;, &#8216;OtherModule2&#8217;));<\/p>\n\n\n\n<p>To unset the related module you can use the following API:<br>$fieldInstance-&gt;unsetRelatedModules(Array(&#8216;OtherModule2&#8217;));<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Set Help Information<\/strong><\/p>\n\n\n\n<p>Providing help information for the module field will be useful to educate users.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>include_once('vtlib\/Vtiger\/Module.php');\n$fieldInstance = new Vtiger_Field();\n$fieldInstance-&gt;name = 'LinkTo';\n...\n$fieldInstance-&gt;helpinfo = 'Relate to an existing contact';\n...\n$blockInstance-&gt;addField($fieldInstance);<\/code><\/pre>\n\n\n\n<p>You can set the help text for an existing field using the following API:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$fieldInstance-&gt;setHelpInfo('HELP CONTENT');<\/code><\/pre>\n\n\n\n<p>NOTE: Given below is the snippet of code that should be added to EditView.php of the existing module to<br>enable Help Icon support.<\/p>\n\n\n\n<p>\/\/ \u2026<br>\/\/ Gather the help information associated with fields<br>$smarty-&gt;assign(&#8216;FIELDHELPINFO&#8217;, vtlib_getFieldHelpInfo($currentModule));<br>\/\/ END<br>\/\/ \u2026<br>if($focus-&gt;mode == &#8216;edit&#8217;) $smarty-&gt;display(&#8216;salesEditView.tpl&#8217;);<br>else $smarty-&gt;display(&#8216;CreateView.tpl&#8217;);<\/p>\n\n\n\n<p>Recommended:<\/p>\n\n\n\n<p>\u27a2 Provide translation mapping for the help info being used for a field.<\/p>\n\n\n\n<p>For example, set the help info as HELP_FILEDNAME_INFO and provide the contents in<br>the language file.<\/p>\n\n\n\n<p>$fieldInstance-&gt;setHelpInfo(&#8216;HELP_FIELDNAME_INFO&#8217;);<\/p>\n\n\n\n<p>In module\/\/language\/en_us.lang.php<\/p>\n\n\n\n<p>$mod_strings = Array(<br>\u2026<br>&#8216;HELP_FIELDNAME_INFO&#8217; =&gt; &#8216;Fieldname help contents should be here&#8217;,<br>\u2026);<\/p>\n\n\n\n<p>\u27a2 Avoid newlines in the help content, you can use tag instead<\/p>\n\n\n\n<p>\u27a2 Preferably escape (&#8216;, \u201c, &lt;, &gt;) with HTML entities like (&#8220;, &lt; &gt;)<\/p>\n\n\n\n<p>\u27a2 It is good to have keep the content less, if you want to provide more details you can link to an external page as shown in the example below:<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Set MassEdit property<\/strong><\/p>\n\n\n\n<p>NOTE: Mass edit feature is available from vtiger 5.1 onwards<\/p>\n\n\n\n<p>You can make the field available for mass editing use the following ways described below:<br>When creating the field you can set the property:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>include_once('vtlib\/Vtiger\/Module.php');<br>$fieldInstance = new Vtiger_Field();<br>$fieldInstance-&gt;name = 'TestField';<br>\u2026<br>$fieldInstance-&gt;masseditable = 1;<br>\u2026<br>$blockInstance-&gt;addField($fieldInstance);<\/code><\/pre>\n\n\n\n<p>If you have an existing field its property can be updated using the API:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$fieldInstance-&gt;setMassEditable(value);<\/code><\/pre>\n\n\n\n<p>The value set for masseditable property has the following meaning:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"137\" src=\"https:\/\/itnotes.apjsoftwares.in\/wp-content\/uploads\/2024\/07\/image-3-1024x137.png\" alt=\"\" class=\"wp-image-2043\" srcset=\"https:\/\/itnotes.apjsoftwares.in\/wp-content\/uploads\/2024\/07\/image-3-1024x137.png 1024w, https:\/\/itnotes.apjsoftwares.in\/wp-content\/uploads\/2024\/07\/image-3-300x40.png 300w, https:\/\/itnotes.apjsoftwares.in\/wp-content\/uploads\/2024\/07\/image-3-768x103.png 768w, https:\/\/itnotes.apjsoftwares.in\/wp-content\/uploads\/2024\/07\/image-3.png 1468w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Step 4: Creating Filters<\/strong><\/p>\n\n\n\n<p>Class Vtiger_Filter provides API to work with a Module&#8217;s custom view or filter. The list view display is controlled via these filters.<br>The example given below describes the way of creating new filter for the module:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>include_once('vtlib\/Vtiger\/Module.php');<br>$filterInstance = new Vtiger_Filter();<br>$filterInstance-&gt;name = 'All';<br>$filterInstance-&gt;isdefault = true;<br>$moduleInstance-&gt;addFilter($filterInstance);<\/code><\/pre>\n\n\n\n<p><strong>Configure fields<br><\/strong>To add fields to the filter you can use the following API:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$filterInstance-&gt;addField($fieldInstance, $columnIndex);<\/code><\/pre>\n\n\n\n<p>Where $columnIndex (optional) is the order\/index at which the field should appear in the list view.<\/p>\n\n\n\n<p><strong>Setup Rules<\/strong><br>Once the field is added to filter you can setup rule (condition) for filtering as well using the<br>following API:<\/p>\n\n\n\n<p>$filterInstance-&gt;addRule($fieldInstance, $comparator, $compareValue,$columnIndex);<\/p>\n\n\n\n<p>Where comparator could be one of the following:<\/p>\n\n\n\n<ul>\n<li>EQUALS<\/li>\n\n\n\n<li>NOT_EQUALS<\/li>\n\n\n\n<li>STARTS_WITH<\/li>\n\n\n\n<li>ENDS_WITH<\/li>\n\n\n\n<li>CONTAINS<\/li>\n\n\n\n<li>DOES_NOT_CONTAINS<\/li>\n\n\n\n<li>LESS_THAN<\/li>\n\n\n\n<li>GREATER_THAN<\/li>\n\n\n\n<li>LESS_OR_EQUAL<\/li>\n\n\n\n<li>GREATER_OR_EQUAL<\/li>\n<\/ul>\n\n\n\n<p>$compareValue is the value against with the field needs to be compared.<br>$columnIndex (optional) is the order at which this rule condition should be applied.<\/p>\n\n\n\n<p><strong>Step 5: Related Lists<\/strong><\/p>\n\n\n\n<p>One module could be associated with multiple records of other module that is displayed under \u201cMore Information\u201d tab on Detail View.<\/p>\n\n\n\n<p>The example given below describes the way of creating a relation between a Payslip and Accounts module:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>include_once('vtlib\/Vtiger\/Module.php');<br>$moduleInstance = Vtiger_Module::getInstance('Payslip');<br>$accountsModule = Vtiger_Module::getInstance('Accounts');<br>$relationLabel = 'Accounts';<br>$moduleInstance-&gt;setRelatedList(<br>$accountsModule, $relationLabel, Array('ADD','SELECT')<br>);<\/code><\/pre>\n\n\n\n<p>With this you can Add one or more Accounts to Payslip records.<br>To drop the relation between the modules use the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$moduleInstance-&gt;unsetRelatedList($targetModuleInstance);<\/code><\/pre>\n\n\n\n<p>About setRelatedList API<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Vtiger_Module-&gt;setRelatedList(&lt;TARGET MODULE&gt;&#91;, &lt;HEADER LABEL&gt;, &lt;ALLOWED ACTIONS&gt;,\n&lt;CALLBACK FUNCTION NAME&gt;]);\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"312\" src=\"https:\/\/itnotes.apjsoftwares.in\/wp-content\/uploads\/2024\/07\/image-4-1024x312.png\" alt=\"\" class=\"wp-image-2048\" srcset=\"https:\/\/itnotes.apjsoftwares.in\/wp-content\/uploads\/2024\/07\/image-4-1024x312.png 1024w, https:\/\/itnotes.apjsoftwares.in\/wp-content\/uploads\/2024\/07\/image-4-300x91.png 300w, https:\/\/itnotes.apjsoftwares.in\/wp-content\/uploads\/2024\/07\/image-4-768x234.png 768w, https:\/\/itnotes.apjsoftwares.in\/wp-content\/uploads\/2024\/07\/image-4.png 1465w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>This API will create an entry in the vtiger_crmentityrel table to keep track of relation between module<br>records. Standard modules available in vtiger CRM handles the relation in separate tables and performs the JOIN to fetch data specific to each module.<\/p>\n\n\n\n<p><strong>Step 6: Sharing Access Rules<\/strong><\/p>\n\n\n\n<p>Sharing access configuration for the module can be done as shown below:<br>The example given below describes the way to configure the Payslip module as Private<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>include_once('vtlib\/Vtiger\/Module.php');<br>$moduleInstance = Vtiger_Module::getInstance('Payslip');<br>$moduleInstance-&gt;setDefaultSharing('Private');<\/code><\/pre>\n\n\n\n<p>The can be one of the following:<\/p>\n\n\n\n<ul>\n<li>Public_ReadOnly<\/li>\n\n\n\n<li>Public_ReadWrite<\/li>\n\n\n\n<li>Public_ReadWriteDelete<\/li>\n\n\n\n<li>Private<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Step 7: Module Tools<\/strong><\/p>\n\n\n\n<p>Features like Import, Export are termed as module tools. Such tools can enabled or disabled as shown below: The example given below describes the way to enable and disable the tools for Payslip module<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>include_once('vtlib\/Vtiger\/Module.php');<br>$moduleInstance = Vtiger_Module::getInstance('Payslip');<br>$module-&gt;enableTools(Array('Import', 'Export'));<br>$module-&gt;disableTools('Export');<\/code><\/pre>\n\n\n\n<p><strong>Optional Step: Module Events<\/strong><\/p>\n\n\n\n<p>To check if your vtiger CRM supports Eventing use the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>include_once('vtlib\/Vtiger\/Event.php');<br>boolean Vtiger_Event::isSupported();<\/code><\/pre>\n\n\n\n<p>To register an event for a module, use the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>include_once('vtlib\/Vtiger\/Event.php');\nVtiger_Event::register('&lt;MODULENAME&gt;','&lt;EVENTNAME&gt;','&lt;HANDLERCLASS&gt;',\n'&lt;HANDLERFILE&gt;);<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"840\" height=\"133\" src=\"https:\/\/itnotes.apjsoftwares.in\/wp-content\/uploads\/2024\/07\/image-5.png\" alt=\"\" class=\"wp-image-2053\" srcset=\"https:\/\/itnotes.apjsoftwares.in\/wp-content\/uploads\/2024\/07\/image-5.png 840w, https:\/\/itnotes.apjsoftwares.in\/wp-content\/uploads\/2024\/07\/image-5-300x48.png 300w, https:\/\/itnotes.apjsoftwares.in\/wp-content\/uploads\/2024\/07\/image-5-768x122.png 768w\" sizes=\"(max-width: 840px) 100vw, 840px\" \/><\/figure>\n\n\n\n<p>Example: Registering event callback before and after save.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if(Vtiger_Event::hasSupport()) {\nVtiger_Event::register(\n'Payslip', 'vtiger.entity.aftersave',\n'PayslipHandler', 'modules\/Payslip\/PayslipHandler.php'\n);\nVtiger_Event::register(\n'Payslip', 'vtiger.entity.beforesave',\n'PayslipHandler', 'modules\/Payslip\/PayslipHandler.php'\n);\n}<\/code><\/pre>\n\n\n\n<p>modules\/Payslip\/PayslipHandler.php<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\nclass PayslipHandler extends VTEventHandler {\nfunction handleEvent($eventName, $data) {\nif($eventName == 'vtiger.entity.beforesave') {\n\/\/ Entity is about to be saved, take required action\n}\nif($eventName == 'vtiger.entity.aftersave') {\n\/\/ Entity has been saved, take next action\n}\n}\n}\n?&gt;<\/code><\/pre>\n\n\n\n<p><strong>Optional Step: Module Webservices<\/strong><\/p>\n\n\n\n<p>You will need to invoke the setup API to enable the support for the custom modules.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>include_once('vtlib\/Vtiger\/Module.php');<br>$moduleInstance = Vtiger_Module::getInstance('Payslip');<br>$moduleInstance-&gt;initWebservice();<\/code><\/pre>\n\n\n\n<p><strong>Complete script to payslip module<\/strong><\/p>\n\n\n\n<p>Here is the complete script (vtlib.Test.Create.Module1.php) which creates the Payslip module<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\/\/ Turn on debugging level\n$Vtiger_Utils_Log = true;\n\ninclude_once('vtlib\/Vtiger\/Menu.php');\r\ninclude_once('vtlib\/Vtiger\/Module.php');\n\n\/\/ Create module instance and save it first\r\n$module = new Vtiger_Module();\r\n$module->name = 'Payslip';\r\n$module->save();\n\n\/\/ Initialize all the tables required\r\n$module->initTables();\r\n\/**\r\n * Creates the following table:\r\n * vtiger_payslip (payslipid INTEGER)\r\n * vtiger_payslipcf(payslipid INTEGER PRIMARY KEY)\r\n * vtiger_payslipgrouprel((payslipid INTEGER PRIMARY KEY, groupname VARCHAR(100))\r\n *\/\n\n\/\/ Add the module to the Menu (entry point from UI)\r\n$menu = Vtiger_Menu::getInstance('Tools');\r\n$menu->addModule($module);\r\n\n\/\/ Add the basic module block\r\n$block1 = new Vtiger_Block();\r\n$block1->label = 'LBL_PAYSLIP_INFORMATION';\r\n$module->addBlock($block1);\n\n\/\/ Add custom block (required to support Custom Fields)\r\n$block2 = new Vtiger_Block();\r\n$block2->label = 'LBL_CUSTOM_INFORMATION';\r\n$module->addBlock($block2);\n\n\/** Create required fields and add to the block *\/\r\n$field1 = new Vtiger_Field();\r\n$field1->name = 'PayslipName';\r\n$field1->table = $module->basetable;\r\n$field1->column = 'payslipname';\r\n$field1->columntype = 'VARCHAR(255)';\r\n$field1->uitype = 2;\r\n$field1->typeofdata = 'V~M';\r\n$block1->addField($field1); \/** Creates the field and adds to block *\/\n\n\/\/ Set at-least one field to identifier of module record\r\n$module->setEntityIdentifier($field1);\n\n$field2 = new Vtiger_Field();\r\n$field2->name = 'PayslipType';\r\n$field2->label = 'Payslip Type';\r\n$field2->columntype = 'VARCHAR(100)';\r\n$field2->uitype = 15;\r\n$field2->typeofdata = 'V~O';\/\/ Varchar~Optional\r\n$block1->addField($field2); \/** table and column are automatically set *\/\n\n$field2->setPicklistValues( Array ('Employee', 'Trainee') );\r\n\n$field3 = new Vtiger_Field();\r\n$field3->name = 'Month';\n$field3->uitype = 23;\r\n$field3->typeofdata = 'D~M'; \/\/ Date~Mandatory\r\n$block1->addField($field3); \/** table, column, label, set to default values *\/\n\n$field4 = new Vtiger_Field();\r\n$field4->name = 'LinkTo';\r\n$field4->label= 'Link To';\r\n$field4->table = 'vtiger_payslip';\r\n$field4->column = 'linkto';\r\n$field4->columntype = 'VARCHAR(100)';\r\n$field4->uitype = 10;\r\n$field4->typeofdata = 'V~O';\r\n$field4->helpinfo = 'Relate to an existing contact';\r\n$block1->addField($field4);\r\n$field4->setRelatedModules(Array('Contacts'));\n\n\/** Common fields that should be in every module, linked to vtiger CRM core table\r\n*\/\r\n$field5 = new Vtiger_Field();\r\n$field5->name = 'assigned_user_id';\r\n$field5->label = 'Assigned To';\r\n$field5->table = 'vtiger_crmentity';\r\n$field5->column = 'smownerid';\r\n$field5->uitype = 53;\r\n$field5->typeofdata = 'V~M';\r\n$block1->addField($field5);\n\n$field6 = new Vtiger_Field();\r\n$field6->name = 'CreatedTime';\r\n$field6->label= 'Created Time';\r\n$field6->table = 'vtiger_crmentity';\r\n$field6->column = 'createdtime';\r\n$field6->uitype = 70;\r\n$field6->typeofdata = 'T~O';\r\n$field6->displaytype= 2;\r\n$block1->addField($field6);\n\n$field7 = new Vtiger_Field();\r\n$field7->name = 'ModifiedTime';\r\n$field7->label= 'Modified Time';\r\n$field7->table = 'vtiger_crmentity';\r\n$field7->column = 'modifiedtime';\r\n$field7->uitype = 70;\r\n$field7->typeofdata = 'T~O';\r\n$field7->displaytype= 2;\r\n$block1->addField($field7);\r\n\/** END *\/\r\n\n\/\/ Create default custom filter (mandatory)\r\n$filter1 = new Vtiger_Filter();\r\n$filter1->name = 'All';\r\n$filter1->isdefault = true;\r\n$module->addFilter($filter1);\n\n\/\/ Add fields to the filter created\r\n$filter1->addField($field1)->addField($field2, 1)->addField($field5, 2);\n\n\/\/ Create one more filter\r\n$filter2 = new Vtiger_Filter();\r\n$filter2->name = 'All2';\r\n$module->addFilter($filter2);\n\n\/\/ Add fields to the filter\r\n$filter2->addField($field1);\n$filter2->addField($field2, 1);\n\n\/\/ Add rule to the filter field\r\n$filter2->addRule($field1, 'CONTAINS', 'Test');\n\r\n\/** Associate other modules to this module *\/\r\n$module->setRelatedList(Vtiger_Module::getInstance('Accounts'), 'Accounts',\r\nArray('ADD','SELECT'));\n\r\n\/** Set sharing access of this module *\/\r\n$module->setDefaultSharing('Private');\n\r\n\/** Enable and Disable available tools *\/\r\n$module->enableTools(Array('Import', 'Export'));\r\n$module->disableTools('Merge');\r\n?>\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Creating a new Entity Module vtlib simplifies the creation of new CRM modules. Developers can&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[39],"tags":[],"_links":{"self":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts\/2015"}],"collection":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/comments?post=2015"}],"version-history":[{"count":21,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts\/2015\/revisions"}],"predecessor-version":[{"id":2062,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts\/2015\/revisions\/2062"}],"wp:attachment":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/media?parent=2015"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/categories?post=2015"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/tags?post=2015"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}