To create a DateTime
field in a custom module in Vtiger 7 CRM using VTlib functions, you’ll need to use the addField
method in conjunction with the Field
and Block
classes.
Here’s a step-by-step guide to create a DateTime
field:
Step 1: Initialize the Module
First, you’ll need to load the module where you want to add the DateTime
field.
$moduleInstance = Vtiger_Module::getInstance('ModuleName'); // Replace 'ModuleName' with your custom module's name
Step 2: Initialize the Block
Next, you’ll need to get the block instance where the new field should be added.
$blockInstance = Vtiger_Block::getInstance('BlockName', $moduleInstance); // Replace 'BlockName' with the name of the block
Step 3: Create the DateTime Field
Now, create the field instance and set the required properties for the DateTime
field.
$fieldInstance = new Vtiger_Field();
$fieldInstance->name = 'date_time_field'; // Field name in the database
$fieldInstance->label = 'Date Time Field'; // Display label of the field
$fieldInstance->uitype = 23; // UI type for DateTime
$fieldInstance->typeofdata = 'DT~O'; // Data type; 'DT' for DateTime, 'O' for optional
$fieldInstance->displaytype = 1; // Display type; 1 means always visible
$fieldInstance->columntype = 'datetime'; // Database column type
$blockInstance->addField($fieldInstance);
Step 4: Save the Changes
Once the field has been created and added to the block, the changes are automatically saved to the database.
Step 5: Assign the Field to Profiles
To make the field available to users with certain profiles, use the following code:
$fieldInstance->setRelatedModules(array('ModuleName')); // Replace 'ModuleName' with the name of the module you want to relate
Additional Notes
- Make sure to replace
'ModuleName'
and'BlockName'
with the actual names of your custom module and block. - The
uitype
forDateTime
in Vtiger is23
. typeofdata
should be set to'DT~O'
for a DateTime field, whereO
denotes that the field is optional (useM
for mandatory).
By following these steps, you can successfully create a DateTime
field in a custom module in Vtiger CRM 7 using VTlib functions. Let me know if you need further assistance!
Conclusion
To make a new field named DateTime simply in any custom module in Vtiger 7 CRM with the help of VTlib operations, then you have to utilize a method named addField in combination with the Block and Field classes while having the best Vtiger hosting solutions.