1

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?

3
  • Your overwriting $block1 object with the result of $block1 = Vtiger_Block::getInstance('LBL_LEAD', $module);, better naming convention I recon Commented Nov 12, 2013 at 21:46
  • 1
    what's print_r($block1) shows if you add it before addField() line? Commented Nov 12, 2013 at 21:46
  • I figured this out anyway - I was overwriting $block1, but apparently I was not assigning the correct label either. Commented Nov 12, 2013 at 22:28

1 Answer 1

5

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'));
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.