{"id":9003,"date":"2024-08-30T07:06:14","date_gmt":"2024-08-30T07:06:14","guid":{"rendered":"https:\/\/www.infinitivehost.com\/knowledge-base\/?p=9003"},"modified":"2024-08-31T08:05:26","modified_gmt":"2024-08-31T08:05:26","slug":"create-datetime-field-in-vtiger-7-crm-module-using-vtlib","status":"publish","type":"post","link":"https:\/\/www.infinitivehost.com\/knowledge-base\/create-datetime-field-in-vtiger-7-crm-module-using-vtlib\/","title":{"rendered":"Create DateTime Field in Vtiger 7 CRM Module Using Vtlib"},"content":{"rendered":"<div class='epvc-post-count'><span class='epvc-eye'><\/span>  <span class=\"epvc-count\"> 1,899<\/span><span class='epvc-label'> Views<\/span><\/div>\n<p>To create a <code>DateTime<\/code> field in a custom module in Vtiger 7 CRM using VTlib functions, you&#8217;ll need to use the <code>addField<\/code> method in conjunction with the <code>Field<\/code> and <code>Block<\/code> classes.<\/p>\n\n\n\n<p>Here&#8217;s a step-by-step guide to create a <code>DateTime<\/code> field:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Initialize the Module<\/h3>\n\n\n\n<p>First, you&#8217;ll need to load the module where you want to add the <code>DateTime<\/code> field.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">$moduleInstance = Vtiger_Module::getInstance('ModuleName'); \/\/ Replace 'ModuleName' with your custom module's name<\/mark><\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Initialize the Block<\/h3>\n\n\n\n<p>Next, you&#8217;ll need to get the block instance where the new field should be added.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">$blockInstance = Vtiger_Block::getInstance('BlockName', $moduleInstance); \/\/ Replace 'BlockName' with the name of the block<\/mark><\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Create the DateTime Field<\/h3>\n\n\n\n<p>Now, create the field instance and set the required properties for the <code>DateTime<\/code> field.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">$fieldInstance = new Vtiger_Field();\n$fieldInstance-&gt;name = 'date_time_field'; \/\/ Field name in the database\n$fieldInstance-&gt;label = 'Date Time Field'; \/\/ Display label of the field\n$fieldInstance-&gt;uitype = 23; \/\/ UI type for DateTime\n$fieldInstance-&gt;typeofdata = 'DT~O'; \/\/ Data type; 'DT' for DateTime, 'O' for optional\n$fieldInstance-&gt;displaytype = 1; \/\/ Display type; 1 means always visible\n$fieldInstance-&gt;columntype = 'datetime'; \/\/ Database column type\n$blockInstance-&gt;addField($fieldInstance);<\/mark><\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 4: Save the Changes<\/h3>\n\n\n\n<p>Once the field has been created and added to the block, the changes are automatically saved to the database.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 5: Assign the Field to Profiles<\/h3>\n\n\n\n<p>To make the field available to users with certain profiles, use the following code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">$fieldInstance-&gt;setRelatedModules(array('ModuleName')); \/\/ Replace 'ModuleName' with the name of the module you want to relate<\/mark><\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Additional Notes<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Make sure to replace <code>'ModuleName'<\/code> and <code>'BlockName'<\/code> with the actual names of your custom module and block.<\/li>\n\n\n\n<li>The <code>uitype<\/code> for <code>DateTime<\/code> in Vtiger is <code>23<\/code>.<\/li>\n\n\n\n<li><code>typeofdata<\/code> should be set to <code>'DT~O'<\/code> for a DateTime field, where <code>O<\/code> denotes that the field is optional (use <code>M<\/code> for mandatory).<\/li>\n<\/ul>\n\n\n\n<p>By following these steps, you can successfully create a <code>DateTime<\/code> field in a custom module in Vtiger CRM 7 using VTlib functions. Let me know if you need further assistance!<\/p>\n\n\n\n<p><strong>Conclusion<\/strong><\/p>\n\n\n\n<p>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 <a href=\"https:\/\/www.infinitivehost.com\/managed-vtiger-solutions\"><mark style=\"background-color:#8ed1fc\" class=\"has-inline-color\"><strong>best Vtiger hosting solutions<\/strong><\/mark><\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1,899 Views To create a DateTime field in a custom module in Vtiger 7 CRM using VTlib functions, you&#8217;ll need to use the addField method in conjunction with the Field and Block classes. Here&#8217;s a step-by-step guide to create a DateTime field: Step 1: Initialize the Module First, you&#8217;ll need to load the module where [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[204],"tags":[],"class_list":["post-9003","post","type-post","status-publish","format-standard","hentry","category-vtiger-solutions"],"_links":{"self":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts\/9003","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/comments?post=9003"}],"version-history":[{"count":2,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts\/9003\/revisions"}],"predecessor-version":[{"id":9040,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts\/9003\/revisions\/9040"}],"wp:attachment":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/media?parent=9003"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/categories?post=9003"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/tags?post=9003"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}