2

I'm newbie in vtiger. I'm trying to insert the field "Service Name" from Services module in TroubleTicket module, but up to now I wasn't able to do it.
Generally speaking, is it possible to insert a field in a Module from another module? If so, how is it supposed to be done?

VMAtm
  • 27,943
  • 17
  • 79
  • 125
rreto
  • 21
  • 1
  • 3

1 Answers1

5

You can use this Code, Put this under your vTiger root directory and call it from browser.

<?php
$Vtiger_Utils_Log = true;

include_once('vtlib/Vtiger/Menu.php');
include_once('vtlib/Vtiger/Module.php');

$module = Vtiger_Module::getInstance('HelpDesk');
if($module) {
$blockInstance = Vtiger_Block::getInstance('LBL_TICKET_INFORMATION', $module);

    if($blockInstance) {

    $fieldInstance = Vtiger_Field::getInstance('Service1', $module);

       if(!$fieldInstance) {
           $fieldInstance = new Vtiger_Field();
           $fieldInstance->name = 'Service1';
           $fieldInstance->label = 'Service Name';
           $fieldInstance->uitype = 10;
           $fieldInstance->typeofdata = 'V~O';
           $blockInstance->addField($fieldInstance);

           $fieldInstance->setRelatedModules(Array('Services'));
       }
  }
}
?>

Salim
  • 196
  • 8
  • Flawless example, thank you, btw if i need more than one field like this case, but with more fields, in that case i just add them to the conditional (if(!$fieldInstance)? – NeoVe Jan 11 '14 at 18:02