1

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
    require_once 'vtlib/Vtiger/Module.php';
    require_once 'modules/ModComments/ModComments.php';

    $commentsModule = Vtiger_Module::getInstance('ModComments');
    $fieldInstance = Vtiger_Field::getInstance('related_to', $commentsModule);
    $fieldInstance->setRelatedModules(array('Laptop'));// Here is my Custom Module Name
    $detailviewblock=ModComments::addWidgetTo('Laptop');
    echo "Comments have been added for Your_Custom_Module_Name Module";
    ?>
    ```

1 Answers1

1

It seems that you are relating the comments module to another one. These are the scripts I use to add and remove ModComments to other modules, just replace MODULE with your module name:

Add:

<?php
    include_once 'vtlib/Vtiger/Module.php';
    require_once 'modules/ModComments/ModComments.php';

    $moduleNames = 'MODULE';

    ModComments::addWidgetTo($moduleNames);
?>

Remove:

<?php
    include_once 'vtlib/Vtiger/Module.php';
    require_once 'modules/ModComments/ModComments.php';

    $moduleNames = 'MODULE';

    ModComments::removeWidgetFrom($moduleNames);
?>

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 add and remove ModComments relationship. – Santosh Kumar Jul 22 '22 at 13:19