William,<div><br></div><div>Fields with uitype 27 and 28 are hardcoded for Documents module and might not work for other modules.</div><div>To relate Documents module with any other module all you need is this</div><div><div>
<font color="#ff0000"><br class="Apple-interchange-newline"></font><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<font color="#ff0000">$module->setRelatedList(Vtiger_Module::getInstance('Documents'), 'Documents', Array('ADD','SELECT'),'get_attachments');</font></blockquote></div><br class="Apple-interchange-newline">
I just tried it for Vendors module and it worked for me.</div><div><br><div class="gmail_quote">On 25 June 2012 21:14, William Bejarano <span dir="ltr"><<a href="mailto:william.bejarano@ito-software.com" target="_blank">william.bejarano@ito-software.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello everybody<div><br></div><div>I created a new module and need add a documents field, I used 27 and 28 Uitype in this script, </div>
<div><br></div><div><div><br></div><div>// Just a bit of HTML formatting</div><div>echo '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "<a href="http://www.w3.org/TR/html4/loose.dtd" target="_blank">http://www.w3.org/TR/html4/loose.dtd</a>">';</div>
<div><br></div><div>echo '<html><head><title>vtlib Module Script</title>';</div><div>echo '<style type="text/css">@import url("themes/softed/style.css");br { display: block; margin: 2px; }</style>';</div>
<div>echo '</head><body class=small style="font-size: 12px; margin: 2px; padding: 2px;">';</div><div>echo '<a href="index.php"><img src="themes/softed/images/vtiger-crm.gif" alt="vtiger CRM" title="vtiger CRM" border=0></a><hr style="height: 1px">';</div>
<div><br></div><div>// Turn on debugging level</div><div>$Vtiger_Utils_Log = true;</div><div><br></div><div>include_once('vtlib/Vtiger/Menu.php');</div><div>include_once('vtlib/Vtiger/Module.php');</div><div>
<br></div><div>// Create module instance and save it first</div><div>$module = new Vtiger_Module();</div><div>$module->name = 'Payslip';</div><div>$module->save();</div><div>$module->initWebservice();</div>
<div><br></div><div>// Initialize all the tables required</div><div>$module->initTables();</div><div>/**</div><div> * Creates the following table:</div><div> * vtiger_payslip (payslipid INTEGER)</div><div> * vtiger_payslipcf(payslipid INTEGER PRIMARY KEY)</div>
<div> * vtiger_payslipgrouprel((payslipid INTEGER PRIMARY KEY, groupname VARCHAR(100))</div><div> */</div><div><br></div><div>// Add the module to the Menu (entry point from UI)</div><div>$menu = Vtiger_Menu::getInstance('Tools');</div>
<div>$menu->addModule($module);</div><div><br></div><div>// Add the basic module block</div><div>$block1 = new Vtiger_Block();</div><div>$block1->label = 'LBL_PAYSLIP_INFORMATION';</div><div>$module->addBlock($block1);</div>
<div><br></div><div>// Add custom block (required to support Custom Fields)</div><div>$block2 = new Vtiger_Block();</div><div>$block2->label = 'LBL_CUSTOM_INFORMATION';</div><div>$module->addBlock($block2);</div>
<div><br></div><div>/** Create required fields and add to the block */</div><div>$field1 = new Vtiger_Field();</div><div>$field1->name = 'payslipname';</div><div>$field1->label = 'PayslipName';</div>
<div>$field1->table = $module->basetable;</div><div>$field1->column = 'payslipname';</div><div>$field1->columntype = 'VARCHAR(255)';</div><div>$field1->uitype = 2;</div><div>$field1->typeofdata = 'V~M';</div>
<div>$block1->addField($field1); /** Creates the field and adds to block */</div><div><br></div><div><font color="#ff0000">/** Create required fields and add to the block */</font></div><div><font color="#ff0000">$fieldDoc2 = new Vtiger_Field();</font></div>
<div><font color="#ff0000">$fieldDoc2->name = 'documentoa';</font></div><div><font color="#ff0000">$fieldDoc2->label = 'documentoa';</font></div><div><font color="#ff0000">$fieldDoc2->table = 'vtiger_notes';</font></div>
<div><font color="#ff0000">$fieldDoc2->column = 'documentoa';</font></div><div><font color="#ff0000">$fieldDoc2->columntype = 'VARCHAR(200)';</font></div><div><font color="#ff0000">$fieldDoc2->uitype = 27;</font></div>
<div><font color="#ff0000">$fieldDoc2->typeofdata = 'V~0';</font></div><div><font color="#ff0000">$block1->addField($fieldDoc2); /** Creates the field and adds to block */</font></div><div><font color="#ff0000">//$fieldDoc2->setRelatedModules(Array('Documents'));</font></div>
<div><font color="#ff0000"><br></font></div><div><font color="#ff0000">/** Create required fields and add to the block */</font></div><div><font color="#ff0000">$fieldDoc3 = new Vtiger_Field();</font></div><div><font color="#ff0000">$fieldDoc3->name = 'documento';</font></div>
<div><font color="#ff0000">$fieldDoc3->label = 'documento';</font></div><div><font color="#ff0000">$fieldDoc3->table = 'vtiger_notes';</font></div><div><font color="#ff0000">$fieldDoc3->column = 'documento';</font></div>
<div><font color="#ff0000">$fieldDoc3->columntype = 'VARCHAR(200)';</font></div><div><font color="#ff0000">$fieldDoc3->uitype = 28;</font></div><div><font color="#ff0000">$fieldDoc3->typeofdata = 'V~0';</font></div>
<div><font color="#ff0000">$block1->addField($fieldDoc3); /** Creates the field and adds to block */</font></div><div><font color="#ff0000">//$fieldDoc3->setRelatedModules(Array('Documents'));</font></div><div>
<br></div><div><br></div><div><br></div><div>// Set at-least one field to identifier of module record</div><div>$module->setEntityIdentifier($field1);</div><div><br></div><div>$field2 = new Vtiger_Field();</div><div>$field2->name = 'PayslipType';</div>
<div>$field2->label = 'Payslip Type'; </div><div>$field2->columntype = 'VARCHAR(100)';</div><div>$field2->uitype = 15;</div><div>$field2->typeofdata = 'V~O';// Varchar~Optional</div><div>
$block1->addField($field2); /** table and column are automatically set */</div><div><br></div><div>$field2->setPicklistValues( Array ('Employee', 'Trainee'));</div><div><br></div><div>$field3 = new Vtiger_Field();</div>
<div>$field3->name = 'Month';</div><div>$field3->uitype = 23;</div><div>$field3->typeofdata = 'D~M'; // Date~Mandatory</div><div>$block1->addField($field3); /** table, column, label, set to default values */</div>
<div><br></div><div>$field4 = new Vtiger_Field();</div><div>$field4->name = 'LinkTo';</div><div>$field4->label= 'Link To';</div><div>$field4->table = 'vtiger_payslip';</div><div>$field4->column = 'linkto';</div>
<div>$field4->columntype = 'VARCHAR(100)';</div><div><br></div><div>$field4->uitype = 10;</div><div>$field4->typeofdata = 'V~O';</div><div>$field4->helpinfo = 'Relate to an existing contact';</div>
<div>$block1->addField($field4);</div><div>$field4->setRelatedModules(Array('Contacts'));</div><div><br></div><div>/** Common fields that should be in every module, linked to vtiger CRM core table */</div><div>
$field5 = new Vtiger_Field();</div><div>$field5->name = 'assigned_user_id';</div><div>$field5->label = 'Assigned To';</div><div>$field5->table = 'vtiger_crmentity'; </div><div>$field5->column = 'smownerid';</div>
<div>$field5->uitype = 53;</div><div>$field5->typeofdata = 'V~M';</div><div>$block1->addField($field5);</div><div><br></div><div>$field6 = new Vtiger_Field();</div><div>$field6->name = 'CreatedTime';</div>
<div>$field6->label= 'Created Time';</div><div>$field6->table = 'vtiger_crmentity';</div><div>$field6->column = 'createdtime';</div><div>$field6->uitype = 70;</div><div>$field6->typeofdata = 'T~O';</div>
<div>$field6->displaytype= 2;</div><div>$block1->addField($field6);</div><div><br></div><div>$field7 = new Vtiger_Field();</div><div>$field7->name = 'ModifiedTime';</div><div>$field7->label= 'Modified Time';</div>
<div>$field7->table = 'vtiger_crmentity';</div><div>$field7->column = 'modifiedtime';</div><div>$field7->uitype = 70;</div><div>$field7->typeofdata = 'T~O';</div><div>$field7->displaytype= 2;</div>
<div>$block1->addField($field7);</div><div>/** END */</div><div><br></div><div>// Create default custom filter (mandatory)</div><div>$filter1 = new Vtiger_Filter();</div><div>$filter1->name = 'All';</div><div>
$filter1->isdefault = true;</div><div>$module->addFilter($filter1);</div><div><br></div><div>// Add fields to the filter created</div><div>$filter1->addField($field1)->addField($field2, 1)->addField($field5, 2);</div>
<div><br></div><div>// Create one more filter</div><div>$filter2 = new Vtiger_Filter();</div><div>$filter2->name = 'All2';</div><div>$module->addFilter($filter2);</div><div><br></div><div>// Add fields to the filter</div>
<div>$filter2->addField($field1);</div><div>$filter2->addField($field2, 1);</div><div><br></div><div>// Add rule to the filter field</div><div>$filter2->addRule($field1, 'CONTAINS', 'Test');</div>
<div><br></div><div>/** Associate other modules to this module */</div><div><font color="#ff0000">$module->setRelatedList(Vtiger_Module::getInstance('Documents'), 'Documents', Array('ADD','SELECT'),'get_attachments');</font></div>
<div><br></div><div>/** Set sharing access of this module */</div><div>$module->setDefaultSharing('Private'); </div><div><br></div><div>/** Enable and Disable available tools */</div><div>$module->enableTools(Array('Import', 'Export'));</div>
<div>$module->disableTools('Merge');</div><div><br></div><div>echo '</body></html>';</div><div><br></div><div><br></div><div>1) The maximum upload size it is equal than 0MB.</div><div>2) When i try upload a document, it isn't saved (I modified the maximum upload with firebug)</div>
<div>3) In the section "<span style="line-height:20px;text-align:-webkit-center;font-size:11px;white-space:nowrap;font-family:Arial,Helvetica,sans-serif;font-weight:bold">More Information</span>" on "document" cannot attach a file</div>
<div><br></div><div>Thks</div><span class="HOEnZb"><font color="#888888"><div><br></div><div><br clear="all"><div><br></div>-- <br><font size="4"><b>William Bejarano</b></font><br>Ing. Sistemas<br><a href="http://www.ito-software.co" target="_blank">www.ito-software.co</a><br>
<br>
</div></font></span></div>
<br>_______________________________________________<br>
<a href="http://www.vtiger.com/" target="_blank">http://www.vtiger.com/</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br>Regards<br>Vikas<br>Vtiger Team<br>
</div>