0

I hope all of you are doing well. I have created 1:M relationship between custom modules and Custom relationship used this script.we have run this script in root folder. 1:M relationship are working fine and relationship view also perfect.

```
<?php

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

$moduleInstance = Vtiger_Module::getInstance('  ');       //Here Custom Module name
$accountsModule = Vtiger_Module::getInstance('Leads');   //Here Relational Modules name
$relationLabel  = 'RelLeads';
$moduleInstance->setRelatedList(
$accountsModule, $relationLabel, Array('ADD','SELECT')
);
 echo"Relation 1:M added between Custom Module and Leads Modules";
?>
```

1 Answers1

0

You can use this script, just replace the values for MODULE, RELMODULE and LABEL:

<?php
/*
destroy_relation.php
Create this file into your root directory of vtiger i.e. vtigercrm/
and then run this file directly using your browser 
for example localhost/vtigercrm/destroy_relation.php
 */
include_once('vtlib/Vtiger/Menu.php');
include_once('vtlib/Vtiger/Module.php');
// Turn on debugging level
$Vtiger_Utils_Log = true;

$moduleInstance = Vtiger_Module::getInstance('MODULE');
$accountsModule = Vtiger_Module::getInstance('RELMODULE');
$relationLabel  = 'LABEL';
$moduleInstance->unsetRelatedList(
      $accountsModule, $relationLabel
);

echo "done";
?>

Keep in mind that this will delete the relation record at vtiger_relatedlists but not the records created at vtiger_crmentityrel. You can delete this records with mysql, searching for the ones whose module and relmodule fields are the ones in your relation.

psauleda
  • 60
  • 5
  • Thank you so much, I was stuck on How to unset 1:M relationship between custom modules and Custom relationship in Vtiger using VTlib library. The code you shared is perfect for unset for leads relationship. But, Other relationship like Comment Mod, Activities,Documents not able to unset the relationship. – Santosh Kumar Jul 13 '22 at 08:19
  • Well, I guess in that case you can straightfully delete the relation record at vtiger_relatedlists with a mysql query. Search for the record whose tabid and related_tabid equals to the modules you are relating (you can search module's id at vtiger_tab), and maybe check also the label to be sure. – psauleda Jul 13 '22 at 08:35