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);
?>
Related
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 am trying to send the order info from Woocommerce into Netsuite as a sale order, when creating a new order. In order to create a new sale order by PHP toolkit, it is necessary for me to create Assembly Items first.
Is there a way to create a new Item using PHP-toolkit?
Here is a PHP code snippet for creating a new Item myself.
$service = new NetSuiteService();
$ai = new AssemblyItem();
// Rustica Group Item Form - 20
$ai->customForm = new RecordRef();
$ai->customForm->internalId = 20;
$ai->memberList = new ItemMemberList();
$item_member = array();
$itemMember = new ItemMember();
$itemMember->internalId = 186625;
$item_member[] = $itemMember;
$ai->memberList->itemMember = $item_member;
$ai->itemId = 'Hardware' . $data['itemId'];
$ai->displayName = $data['displayName'];
$ai->vendorName = '';
$ai->cost = $data['price'];
$ai->isTaxable = $data['taxable'];
$ai->description = $data['description'];
$request = new AddRequest();
$request->record = $ai;
$addResponse = $service->add($request);
print_r($addResponse);
if (!$addResponse->writeResponse->status->isSuccess) {
return "ADD ERROR";
} else {
return $addResponse->writeResponse->baseRef->internalId;
}
There is no internalid field for ItemMember. Look at the schema
Should look like this...
$itemMember = new ItemMember();
$itemMember->item = new RecordRef();
$itemMember->item->internalId = 186625;
You're missing taxSchedule too..not sure if you are confusing that with isTaxable
$ai->taxSchedule = new RecordRef();
$ai->taxSchedule->internalId = 1; //whatever tax schedule you're using
You should pre-store the item of the product before saving the product that you want to send from Woocommerce into Netsuite.
If you store the item on netsuite, they will return the internal_id of the item.
Then, you can save the item with internal id that they return.
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've written this code for vTiger, trying to tie the Quote module into a field for the Lead module:
$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');
// Create Block instance
$block1 = new Vtiger_Block();
$block1->label = 'Block Name';
$block1 = Vtiger_Block::getInstance('LBL_LEAD', $module);
$field0 = new Vtiger_Field();
$field0->name = 'Leads';
$field0->label = 'Leads';
$field0->uitype = 10;
$field0->typeofdata = 'V~O';
$field0->setRelatedModules(Array('Quotes'));
$block1->addField($field0);
This is the response I'm getting:
Setting Leads relation with Quotes ... DONE
Fatal error: Call to a member function addField() on a non-object in /var/www/duvtiger/vtigerscript.php on line 23
Why is $block1 not an object?
How do I fix this? What am I doing wrong? This is all I have to do to setup the related field, correct?
try this code to add new related field. This will surely helps you. You have set relation before adding field that's why the error you getting is "block1 is not an object".
$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 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');
?>