I am new to Vtiger CRM and I have searched a lot to find how to create a custom module in Vtiger CRM with a table associated with it from scratch. I am not able to follow the documentation provided by Vtiger.
Refer this url for Creating New module and fields.
https://wiki.vtiger.com/index.php/CreatingEntityModule
Or if you having any problem then follow as per instructions.
first of all do this.
First create a new folder(module name without space) in modules and copy files from vtlib/ModuleDir/5.4.0 file to the folder created in modules/newmodule
Change name of ModuleFile.js, ModuleFile.php, ModuleFileAjax.php with your module name(with no space).
Keep in mind, During changing name of ModuleFileAjax.php just Replace ModuleFile with name of Module.
Go to modulename.php to change the class name, $table_name (6values change), $table_index (4values change).
Create new file with any name. Insert the code below to add the fields and also module.
<?php
// Turn on debugging level
$Vtiger_Utils_Log = true;
include_once('vtlib/Vtiger/Menu.php');
include_once('vtlib/Vtiger/Module.php');
$module = new Vtiger_Module();
$module->name = 'Store';//(No space in module name)
$module->save();
$module->initTables();
$module->initWebservice();
$menu = Vtiger_Menu::getInstance('Support');
$menu->addModule($module);
$block1 = new Vtiger_Block();
$block1->label = 'Organization Information';
$module->addBlock($block1); //to create a new block
$field0 = new Vtiger_Field();
$field0->name = 'organization_name';
$field0->label = 'Organization Name';
$field0->table = $module->basetable;
$field0->column = 'organization_name';
$field0->columntype = 'VARCHAR(100)';
$field0->uitype = 2;
$field0->typeofdata = 'V~M';
$module->setEntityIdentifier($field0); //to insert values in entity folder
$block1->addField($field0); //to add field in block
$field1 = new Vtiger_Field();
$field1->name = 'store_id_auto';
$field1->label = 'Store ID';
$field1->table = $module->basetable;
$field1->column = 'store_id_auto';
$field1->columntype = 'VARCHAR(100)';
$field1->uitype = 4;
$field1->typeofdata = 'V~O';
$block1->addField($field1);
//Do not change any value for filed2.
$field2 = new Vtiger_Field();
$field2->name = 'assigned_user_id';
$field2->label = 'Assigned To';
$field2->table = 'vtiger_crmentity';
$field2->column = 'smownerid';
$field2->columntype = 'int(19)';
$field2->uitype = 53;
$field2->typeofdata = 'V~M';
$block1->addField($field2);
$filter1 = new Vtiger_Filter();
$filter1->name = 'All';
$filter1->isdefault = true;
$module->addFilter($filter1);
// Add fields to the filter created
$filter1->addField($field0, 1);
$filter1->addField($field1, 2);
$filter1->addField($field2, 3);
/** Set sharing access of this module */
$module->setDefaultSharing('Private');
/** Enable and Disable available tools */
$module->enableTools(Array('Import', 'Export'));
$module->disableTools('Merge');
?>
we have Create Store module
Create folder in modules/Store and also create Store.php file in Store folder
modules/Store/Store.php
include_once 'modules/Vtiger/CRMEntity.php';
class Store extends Vtiger_CRMEntity {
var $table_name = 'vtiger_store';
var $table_index= 'storeid';
var $customFieldTable = Array('vtiger_storecf', 'storeid');
var $tab_name = Array('vtiger_crmentity', 'vtiger_store', 'vtiger_storecf');
var $tab_name_index = Array(
'vtiger_crmentity' => 'crmid',
'vtiger_store' => 'storeid',
'vtiger_storecf'=>'storeid');
var $list_fields = Array (
/* Format: Field Label => Array(tablename, columnname) */
// tablename should not have prefix 'vtiger_'
'Organization Name' => Array('store', 'organization_name'),
'Assigned To' => Array('crmentity','smownerid')
);
var $list_fields_name = Array (
/* Format: Field Label => fieldname */
'Organization Name' => 'organization_name',
'Assigned To' => 'assigned_user_id',
);
// Make the field link to detail view
var $list_link_field = 'organization_name';
// For Popup listview and UI type support
var $search_fields = Array(
/* Format: Field Label => Array(tablename, columnname) */
// tablename should not have prefix 'vtiger_'
'Organization Name' => Array('store', 'organization_name'),
'Assigned To' => Array('vtiger_crmentity','assigned_user_id'),
);
var $search_fields_name = Array (
/* Format: Field Label => fieldname */
'Organization Name' => 'organization_name',
'Assigned To' => 'assigned_user_id',
);
// For Popup window record selection
var $popup_fields = Array ('organization_name');
// For Alphabetical search
var $def_basicsearch_col = 'organization_name';
// Column value to use on detail view record text display
var $def_detailview_recname = 'organization_name';
// Used when enabling/disabling the mandatory fields for the module.
// Refers to vtiger_field.fieldname values.
var $mandatory_fields = Array('organization_name','assigned_user_id');
var $default_order_by = 'organization_name';
var $default_sort_order='ASC';
}
Create languages/en_us/Store.php
<?php
$languageStrings = array(
'SINGLE_Store'=>'Store'
);
?>
Create file /var/www/html/Projectname/Store.php and run this file
<?php
// Turn on debugging level
$Vtiger_Utils_Log = true;
include_once('vtlib/Vtiger/Menu.php');
include_once('vtlib/Vtiger/Module.php');
$module = new Vtiger_Module();
$module->name = 'Store';//(No space in module name)
$module->save();
$module->initTables();
$module->initWebservice();
$menu = Vtiger_Menu::getInstance('Support');
$menu->addModule($module);
$block1 = new Vtiger_Block();
$block1->label = 'Organization Information';
$module->addBlock($block1); //to create a new block
$field0 = new Vtiger_Field();
$field0->name = 'organization_name';
$field0->label = 'Organization Name';
$field0->table = $module->basetable;
$field0->column = 'organization_name';
$field0->columntype = 'VARCHAR(100)';
$field0->uitype = 2;
$field0->typeofdata = 'V~M';
$module->setEntityIdentifier($field0); //to insert values in entity folder
$block1->addField($field0); //to add field in block
$field1 = new Vtiger_Field();
$field1->name = 'store_id_auto';
$field1->label = 'Store ID';
$field1->table = $module->basetable;
$field1->column = 'store_id_auto';
$field1->columntype = 'VARCHAR(100)';
$field1->uitype = 4;
$field1->typeofdata = 'V~O';
$block1->addField($field1);
//Do not change any value for filed2.
$field2 = new Vtiger_Field();
$field2->name = 'assigned_user_id';
$field2->label = 'Assigned To';
$field2->table = 'vtiger_crmentity';
$field2->column = 'smownerid';
$field2->columntype = 'int(19)';
$field2->uitype = 53;
$field2->typeofdata = 'V~M';
$block1->addField($field2);
$field3 = new Vtiger_Field();
$field3->name = 'CreatedTime';
$field3->label= 'Created Time';
$field3->table = 'vtiger_crmentity';
$field3->column = 'createdtime';
$field3->uitype = 70;
$field3->typeofdata = 'T~O';
$field3->displaytype= 2;
$block->addField($field3);
$field4 = new Vtiger_Field();
$field4->name = 'ModifiedTime';
$field4->label= 'Modified Time';
$field4->table = 'vtiger_crmentity';
$field4->column = 'modifiedtime';
$field4->uitype = 70;
$field4->typeofdata = 'T~O';
$field4->displaytype= 2;
$block->addField($field4);
$filter1 = new Vtiger_Filter();
$filter1->name = 'All';
$filter1->isdefault = true;
$module->addFilter($filter1);
// Add fields to the filter created
$filter1->addField($field0, 1);
$filter1->addField($field1, 2);
$filter1->addField($field2, 3);
/** Set sharing access of this module */
$module->setDefaultSharing('Private');
/** Enable and Disable available tools */
$module->enableTools(Array('Import', 'Export'));
$module->disableTools('Merge');
?>
Related
I hope all of you are doing well.
I have created a custom module used this script.we have run this script in root folder.All field are working fine and list view also perfect.
```
<?php
include_once 'vtlib/Vtiger/Module.php';
include_once 'vtlib/Vtiger/Package.php';
include_once 'includes/main/WebUI.php';
include_once 'include/Webservices/Utils.php';
$Vtiger_Utils_Log = true;
$MODULENAME = 'Laptop';
$moduleInstance = Vtiger_Module::getInstance($MODULENAME);
if ($moduleInstance || file_exists('modules/'.$MODULENAME)) {
echo "Module already present - choose a different name.";
} else {
$moduleInstance = new Vtiger_Module();
$moduleInstance->name = $MODULENAME;
$moduleInstance->parent= 'Tools';
$moduleInstance->save();
// Schema Setup
$moduleInstance->initTables();
// Field Setup
$block = new Vtiger_Block();
$block->label = 'LBL_'. strtoupper($moduleInstance->name) . '_INFORMATION';
$moduleInstance->addBlock($block);
$blockcf = new Vtiger_Block();
$blockcf->label = 'LBL_CUSTOM_INFORMATION';
$moduleInstance->addBlock($blockcf);
// Text Area1 Item_Name
$itemName = new Vtiger_Field();
$itemName->name = 'itemname';
$itemName->label= 'Item Name';
$itemName->uitype= 1;
$itemName->column = $itemName->name;
$itemName->columntype = 'VARCHAR(100)';
$itemName->typeofdata = 'V~M';
$block->addField($itemName);
// Text Area2 Item_Deatils
$itemdeatils = new Vtiger_Field();
$itemdeatils->name = 'itemdeatils';
$itemdeatils->label= 'Item Deatils';
$itemdeatils->uitype= 1;
$itemdeatils->column = $itemdeatils->name;
$itemdeatils->columntype = 'VARCHAR(100)';
$itemdeatils->typeofdata = 'V~O';
$block->addField($itemdeatils);
$moduleInstance->setEntityIdentifier($itemdeatils);
// Text Area3 Item_Company.
$companyname = new Vtiger_Field();
$companyname->name = 'companyname';
$companyname->label= 'Company Name.';
$companyname->uitype= 15;
$companyname->column = $companyname->name;
$companyname->columntype = 'VARCHAR(100)';
$companyname->typeofdata = 'V~O';
$block->addField($companyname);
$companyname->setPicklistValues( Array ('Sumsung','HP','Dell', 'Lenovo','Apple') );
$description = new Vtiger_Field();
$description->name = 'description';
$description->label= 'Description';
$description->uitype= 19;
$description->column = 'description';
$description->table = 'vtiger_crmentity';
$blockcf->addField($description);
// Recommended common fields every Entity module should have (linked to core table)
$mfield1 = new Vtiger_Field();
$mfield1->name = 'assigned_user_id';
$mfield1->label = 'Assigned To';
$mfield1->table = 'vtiger_crmentity';
$mfield1->column = 'smownerid';
$mfield1->uitype = 53;
$mfield1->typeofdata = 'V~M';
$block->addField($mfield1);
$mfield2 = new Vtiger_Field();
$mfield2->name = 'createdtime';
$mfield2->label= 'Created Time';
$mfield2->table = 'vtiger_crmentity';
$mfield2->column = 'createdtime';
$mfield2->uitype = 70;
$mfield2->typeofdata = 'DT~O';
$mfield2->displaytype= 2;
$block->addField($mfield2);
$mfield3 = new Vtiger_Field();
$mfield3->name = 'modifiedtime';
$mfield3->label= 'Modified Time';
$mfield3->table = 'vtiger_crmentity';
$mfield3->column = 'modifiedtime';
$mfield3->uitype = 70;
$mfield3->typeofdata = 'DT~O';
$mfield3->displaytype= 2;
$block->addField($mfield3);
/* NOTE: Vtiger 7.1.0 onwards */
$mfield4 = new Vtiger_Field();
$mfield4->name = 'source';
$mfield4->label = 'Source';
$mfield4->table = 'vtiger_crmentity';
$mfield4->displaytype = 2; // to disable field in Edit View
$mfield4->quickcreate = 3;
$mfield4->masseditable = 0;
$block->addField($mfield4);
$mfield5 = new Vtiger_Field();
$mfield5->name = 'starred';
$mfield5->label = 'starred';
$mfield5->table = 'vtiger_crmentity_user_field';
$mfield5->displaytype = 6;
$mfield5->uitype = 56;
$mfield5->typeofdata = 'C~O';
$mfield5->quickcreate = 3;
$mfield5->masseditable = 0;
$block->addField($mfield5);
$mfield6 = new Vtiger_Field();
$mfield6->name = 'tags';
$mfield6->label = 'tags';
$mfield6->displaytype = 6;
$mfield6->columntype = 'VARCHAR(1)';
$mfield6->quickcreate = 3;
$mfield6->masseditable = 0;
$block->addField($mfield6);
/* End 7.1.0 */
// Filter Setup
$filter1 = new Vtiger_Filter();
$filter1->name = 'All';
$filter1->isdefault = true;
$moduleInstance->addFilter($filter1);
$filter1->addField($itemName);
$filter1->addField($itemdeatils, 1);
$filter1->addField($companyname, 2);
$filter1->addField($mfield1, 3);
// Sharing Access Setup
$moduleInstance->setDefaultSharing('Private');
// Webservice Setup
$moduleInstance->initWebservice();
$targetpath = 'modules/' . $moduleInstance->name;
if (! is_file($targetpath)) {
mkdir($targetpath);
$templatepath = 'vtlib/ModuleDir/6.0.0';
$moduleFileContents = file_get_contents($templatepath . '/ModuleName.php');
$replacevars = array(
'ModuleName' => $moduleInstance->name,
'<modulename>' => strtolower($moduleInstance->name),
'<entityfieldlabel>' => $field1->label,
'<entitycolumn>' => $field1->column,
'<entityfieldname>' => $field1->name
);
foreach ($replacevars as $key => $value) {
$moduleFileContents = str_replace($key, $value, $moduleFileContents);
}
file_put_contents
($targetpath . '/' . $moduleInstance->name . '.php',$moduleFileContents);
}
if (! file_exists('languages/en_us/ModuleName.php')) {
$ModuleLanguageContents = file_get_contents
($templatepath . '/languages/en_us /ModuleName.php');
$replaceparams = array(
'Module Name' => $moduleInstance->name,
'Custom' => $moduleInstance->name,
'ModuleBlock' => $moduleInstance->name,
'ModuleFieldLabel Text' => $field1->label
);
foreach ($replaceparams as $key => $value) {
$ModuleLanguageContents = str_replace($key, $value, $ModuleLanguageContents);
}
$languagePath = 'languages/en_us';
file_put_contents
($languagePath . '/' . $moduleInstance->name . '.php',$ModuleLanguageContents);
}
}
Settings_MenuEditor_Module_Model::addModuleToApp
($moduleInstance->name, $moduleInstance->parent);
?>
```
how can i export & Import custom modules as Package using PHP Script (Vtlib Function) from my CRM vtiger 7, Please help me.
I was stuck on How to create a custom module in Vtiger using VTlib library. The code you shared is perfect for creating custom module in vtiger.
To Export your custom module in vtiger, you need to run the code below -
require_once('vtlib/Vtiger/Package.php');
require_once('vtlib/Vtiger/Module.php');
$package = new Vtiger_Package();
$package->export(
Vtiger_Module::getInstance('Payslip'),
'test/vtlib',
'Payslip-Export.zip',
true
);
Don't forget to change the module name
I have PHP code for Advanced Search items in NetSuite,
but I don't know how I can combine to my search - filtering by item name.
My code is:
$service = new NetSuiteService($config);
$service->setSearchPreferences(true, $page_size, true);
$savedSearchId = '###';
$searchAdvanced = new ItemSearchAdvanced();
setFields($searchAdvanced, array('savedSearchScriptId'=>$savedSearchId));
$request = new SearchRequest();
$request->searchRecord = $searchAdvanced;
$results = $service->search($request);
I want to combine a criteria
Here's sample code I found to get inventory details using Item internal id as a filter. You can reference Suite Answer 90401, 37585, and 25066.
<?php
require_once '../PHPToolkit/NetSuiteService.php';
$service = new NetSuiteService();
// formulate the criteria
$itemRecord = new RecordRef();
$itemRecord--->internalId = 140;
$itemMultiSelect = new SearchMultiSelectField();
$itemMultiSelect->operator = 'anyOf';
$itemMultiSelect->searchValue = $itemRecord;
$itemSearchBasic = new ItemSearchBasic();
$itemSearchBasic->internalId = $itemMultiSelect;
$criteria = new ItemSearch();
$criteria->basic = $itemSearchBasic;
// formulate the resulting columns
$searchRowBasic = new ItemSearchRowBasic();
$searchRowBasic->itemId = new SearchColumnStringField(); // Item Name/Number in UI
$searchRowBasic->internalId = new SearchColumnSelectField(); // Internal ID in UI
$searchRowBasic->location = new SearchColumnSelectField(); // Location (Main section of Inventory Item) in UI
$searchRowBasic->inventoryLocation = new SearchColumnSelectField(); // Location column in Locations tab (Inventory Item) in UI
$searchRowBasic->locationQuantityOnHand = new SearchColumnDoubleField();// Quantity on Hand column in Locations tab (Inventory Item) in UI
$columns = new ItemSearchRow();
$columns->basic = $searchRowBasic;
// item search advanced
$search = new ItemSearchAdvanced();
$search->criteria = $criteria;
$search->columns = $columns;
$request = new SearchRequest();
$request->searchRecord = $search;
$searchResponse = $service->search($request);
if (!$searchResponse->searchResult->status->isSuccess) {
echo "SEARCH ERROR";
} else {
echo "SEARCH SUCCESS, records found: " . $searchResponse->searchResult->totalRecords ;
}
?>
I see a bunch of examples of how to add a new order however I'm trying to update a custom field of an existing order using the PHP toolkit. Could anyone start me out with this? I'm not sure where to start.
This is the code to add a new order
<?php
require_once '../PHPToolkit/NetSuiteService.php';
$service = new NetSuiteService();
$svr = new getSelectValueRequest();
$svr->fieldDescription = new GetSelectValueFieldDescription();
$svr->pageIndex = 1;
$priceFields = array(
'recordType' => RecordType::salesOrder,
'sublist' => 'itemList',
'field' => 'price',
'filterByValueList' => array(
'filterBy' => array(
array(
'field' => 'item',
'sublist' => 'itemList',
'internalId' => '458',
)
)
)
);
if ($id != null) {
echo "Custom price level id is " . $id . "\n";
} else {
echo "Custom price level not found " . $id . "\n";
}
$so = new SalesOrder();
$so->entity = new RecordRef();
$so->entity->internalId = 21;
$so->itemList = new SalesOrderItemList();
$soi = new SalesOrderItem();
$soi->item = new RecordRef();
$soi->item->internalId = 104;
$soi->quantity = 3;
$soi->price = new RecordRef();
$soi->price->internalId = $id;
$soi->amount = 55.3;
$so->itemList->item = array($soi);
$request = new AddRequest();
$request->record = $so;
$addResponse = $service->add($request);
if (!$addResponse->writeResponse->status->isSuccess) {
echo "ADD ERROR";
exit();
} else {
echo "ADD SUCCESS, id " . $addResponse->writeResponse->baseRef->internalId;
}
?>
You'll need a customFieldList object, which is an array of custom fields. There are different objects for the different data types of custom fields - below would be a string custom field. I utf8_encode to deal with weird characters that you normally don't see.
$customFieldList = new CustomFieldList();
$customField = new StringCustomFieldRef();
$customField->value = utf8_encode("contents of string custom field");
$customField->internalId = 'custbody_whatever_your_field_is';
$customFieldList->customField[] = $customField;
$so->customFieldList = $customFieldList;
For some reason, my code is generating module=undefined:
/index.php?module=undefined&action=Popup&html=Popup_picker&form=vtlibPopupView&forfield=Quotes&srcmodule=Leads&forrecord=1695
The problem is that I define the module directly in my script:
$field0->setRelatedModules(Array('Quotes'));
What am I doing wrong here?
Here's my complete code:
$Vtiger_Utils_Log = true;
include_once('vtlib/Vtiger/Menu.php');
include_once('vtlib/Vtiger/Module.php');
//(module name without space)
$module = Vtiger_Module::getInstance('Leads');
$module->initWebservice();
// Create Block instance
$block1 = new Vtiger_Block();
$block1 = Vtiger_Block::getInstance('LBL_LEAD_INFORMATION', $module);
$field0 = new Vtiger_Field();
$field0->name = 'quotes';
$field0->column = 'quotes';
$field0->label = 'Test2';
$field0->uitype = 10;
$field0->typeofdata = 'V~O';
//$field0->setRelatedModules(Array('Quotes'));
$field0->setRelatedModules(Array('quotes'));
$block1->addField($field0);
You have to set related module after adding the field. You can't set relation to any module before adding field.
Add the code below to the addField line.
$block1->addField($field0);
$field0->setRelatedModules(Array('Quotes'));
And also i think you have to add field to table the lead table.
So update your code like this.
$field0 = new Vtiger_Field();
$field0->name = 'quotes';
$field0->column = 'quotes';
$field0->table = $module->basetable;
$field0->label = 'Test2';
$field0->uitype = 10;
$field0->typeofdata = 'V~O';
$block1->addField($field0);
$field0->setRelatedModules(Array('Quotes'));
I want to add new field to vtiger_activity table in vtiger crm. I added the column in the table but now I am not getting place from where the insert function is called, and also how to add this new field to the column list through php code.
thanks
You can add field from module setting-> Layout Editor-> Add Custom Filed Or if you want to add field by using code then here below is the code.
<?php
$Vtiger_Utils_Log = true;
include_once('vtlib/Vtiger/Menu.php');
include_once('vtlib/Vtiger/Module.php');
//(module name without space)
$module = new Vtiger_Module();
$module->name = 'Modulename';
$module = $module->getInstance('Modulename');
// Create Block instance
$block1 = new Vtiger_Block();
$block1->label = 'Block Name';
$block1 = $block1->getInstance($block1->label,$module);
$field0 = new Vtiger_Field();
$field0->name = 'field name';
$field0->table = $module->basetable;
$field0->label = 'Field Name to display';
$field0->column = 'field name';
$field0->columntype = 'VARCHAR(100)';
$field0->uitype = 2;
$field0->typeofdata = 'V~O';
$block1->addField($field0);
?>