<meta http-equiv="content-type" content="text/html; charset=utf-8"><span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: medium; "><pre>Al,</pre><pre>Adding a uitype 10 field will give you a n:1 relationship between Projects:Contacts, which is the opposite of what you are trying to do.</pre>
<pre>(and btw, I think you would have to use "$fieldInstance->setRelatedModules(Array('Contacts'));" for your example to work)</pre><pre>(and btw2: "$fieldInstance->unsetRelatedModules(Array('Contacts')); $fieldInstance->delete();" should clear the field)</pre>
<pre>What you are looking for is a 1:n relationship.</pre><pre>Here's an example to add a 1:n relationship between Projects:Assets</pre><pre><?php</pre><pre>// Just a bit of HTML formatting
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "<a href="http://www.w3.org/TR/html4/loose.dtd">http://www.w3.org/TR/html4/loose.dtd</a>">';
echo '<html><head><title>vtlib Module Script</title>';
echo '<style type="text/css">@import url("themes/softed/style.css");br { display: block; margin: 2px; }</style>';
echo '</head><body class=small style="font-size: 12px; margin: 2px; padding: 2px;">';
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">';
// Turn on debugging level
$Vtiger_Utils_Log = true;
include_once('vtlib/Vtiger/Menu.php');
include_once('vtlib/Vtiger/Module.php');
//Relate projects with Assets 1:n
$moduleaccount = Vtiger_Module::getInstance('Assets');
$moduleaccount->setRelatedList(Vtiger_Module::getInstance('Project'), 'Project','');
echo '</body></html>';
?></pre><pre><br></pre><pre>On 01/07/10 14:59, Alan Lord (News) wrote:
><i> On 01/07/10 07:58, Alan Lord (News) wrote:
</i>><i>
</i>>><i> On 30/06/10 17:27, Joe Bordes wrote:
</i>>><i>
</i>>>><i> uitype 10 and setRelatedList
</i>>>><i> Have a read here: <a href="http://crmevolutivo.com/wiki/doku.php?id=vtlibrelated">http://crmevolutivo.com/wiki/doku.php?id=vtlibrelated</a>
</i>>>><i>
</i>>><i> Thanks Joe,
</i>>><i>
</i>>><i> That looks like just the ticket ;-)
</i>>><i>
</i>><i> OK - Been playing with this a bit.
</i>><i>
</i>><i> Nearly got it right I think... But how can I delete a field I've added?
</i>><i> I now have two :-) I do not see a delField() function.
</i>><i>
</i>><i> I did this in a quick script:
</i>><i>
</i>><i> // Get Module Objects
</i>><i> $project = Vtiger_Module::getInstance('Project');
</i>><i> $contacts = Vtiger_Module::getInstance('Contacts');
</i>><i>
</i>><i> // Get Main Block
</i>><i> $proj_info_block = Vtiger_Block::getInstance('LBL_PROJECT_INFORMATION',
</i>><i> $project);
</i>><i>
</i>><i> // Create and add a UI Type 10 (Popup) Field
</i>><i> $fieldInstance = new Vtiger_Field();
</i>><i> $fieldInstance->name = 'Contact';
</i>><i> $fieldInstance->uitype = 10;
</i>><i> $fieldInstance->setRelatedModules('Contacts');
</i>><i>
</i>><i> $proj_info_block->addField($fieldInstance);
</i>><i>
</i>><i> // Add a 1:n relationship between $project& $contacts
</i>><i> $project->setRelatedList($contacts, 'header',
</i>><i> Array('ADD'),'get_dependents_list');
</i>><i>
</i>><i>
</i>><i> Which "nearly" works.
</i>><i>
</i>><i> I have a new UI Type 10 field in the Project Module, but there is an
</i>><i> empty "Related To" picklist and clicking on the plus sign brings up the
</i>><i> box but with the error "Module name is missing. Please check the module
</i>><i> name."
</i>><i>
</i>><i> Incidentally, adding this field, seems to make it more a 1:1
</i>><i> relationship and I'd need to add "n" fields.
</i>><i>
</i>><i> Am I being thick?
</i>><i>
</i>><i> Sorry.
</i>><i>
</i>><i> Al
</i>><i>
</i>><i>
</i>><i>
</i>>><i> Cheers
</i>>><i>
</i>>><i> Al</i></pre></span>