{"id":8971,"date":"2024-08-27T07:52:59","date_gmt":"2024-08-27T07:52:59","guid":{"rendered":"https:\/\/www.infinitivehost.com\/knowledge-base\/?p=8971"},"modified":"2024-08-31T08:01:20","modified_gmt":"2024-08-31T08:01:20","slug":"remove-11-crm-module-relationships-with-php-in-vtiger-7","status":"publish","type":"post","link":"https:\/\/www.infinitivehost.com\/knowledge-base\/remove-11-crm-module-relationships-with-php-in-vtiger-7\/","title":{"rendered":"Remove 1:1 CRM Module Relationships with PHP in Vtiger 7"},"content":{"rendered":"<div class='epvc-post-count'><span class='epvc-eye'><\/span>  <span class=\"epvc-count\"> 1,134<\/span><span class='epvc-label'> Views<\/span><\/div>\n<p class=\"wp-block-paragraph\">To delete or remove a 1:1 relationship between (CRM Module) custom modules in Vtiger CRM 7 using a PHP script with vtlib functions, you need to follow these general steps:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Load Vtiger Framework<\/strong>: Ensure your script includes the necessary Vtiger framework files to interact with the CRM.<\/li>\n\n\n\n<li><strong>Identify Modules<\/strong>: Identify the custom modules involved in the relationship.<\/li>\n\n\n\n<li><strong>Remove Relationship<\/strong>: Use the vtlib functions to remove the relationship between these modules.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s a sample PHP script demonstrating how to remove a 1:1 relationship between two custom modules, <code>CustomModule1<\/code> and <code>CustomModule2<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\"><code>&lt;?php\n\/\/ Load Vtiger framework\nrequire_once 'include\/entryPoint.php';\nrequire_once 'include\/utils\/CommonUtils.php';\nrequire_once 'include\/utils\/UserInfoUtil.php';\nrequire_once 'modules\/Vtiger\/CRMEntity.php';\nrequire_once 'vtlib\/Vtiger\/Module.php';\n\n\/\/ Function to remove the relationship\nfunction removeRelationship($module1, $module2) {\n    global $adb;\n\n    \/\/ Get module instances\n    $moduleInstance1 = Vtiger_Module::getInstance($module1);\n    $moduleInstance2 = Vtiger_Module::getInstance($module2);\n\n    if ($moduleInstance1 &amp;&amp; $moduleInstance2) {\n        \/\/ Get the relationship type between the two modules\n        $relationInfo = Vtiger_Relation_Model::getInstance($moduleInstance1, $moduleInstance2);\n\n        if ($relationInfo) {\n            \/\/ Delete the relationship\n            $relationInfo-&gt;delete();\n            echo \"1:1 relationship between $module1 and $module2 has been removed successfully.\";\n        } else {\n            echo \"No relationship found between $module1 and $module2.\";\n        }\n    } else {\n        echo \"One or both modules not found.\";\n    }\n}\n\n\/\/ Define your custom modules\n$customModule1 = 'CustomModule1'; \/\/ Replace with your actual custom module name\n$customModule2 = 'CustomModule2'; \/\/ Replace with your actual custom module name\n\n\/\/ Remove the relationship\nremoveRelationship($customModule1, $customModule2);\n\n?&gt;<\/code><\/mark><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Explanation:<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Load Vtiger Framework<\/strong>: The <code>require_once<\/code> statements include necessary Vtiger files to ensure your script can interact with the Vtiger CRM framework.<\/li>\n\n\n\n<li><strong>Define Modules<\/strong>: You define the custom modules you want to work with (<code>CustomModule1<\/code> and <code>CustomModule2<\/code>). Replace these placeholders with the actual module names.<\/li>\n\n\n\n<li><strong>Get Module Instances<\/strong>: Using <code>Vtiger_Module::getInstance()<\/code>, you get the instances of the modules.<\/li>\n\n\n\n<li><strong>Check Relationship<\/strong>: The <code>Vtiger_Relation_Model::getInstance()<\/code> function checks for the existing relationship between the modules.<\/li>\n\n\n\n<li><strong>Delete Relationship<\/strong>: If the relationship exists, you call the <code>delete()<\/code> method to remove it.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Notes:<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Ensure you have appropriate permissions and backup your CRM data before running any scripts that modify relationships.<\/li>\n\n\n\n<li>This script assumes that the <code>Vtiger_Relation_Model<\/code> class and its methods are available and that the CRM is properly configured.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Make sure to test this script in a development environment before applying it to your live CRM system to avoid any unintended consequences.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Conclusion<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To simply remove or delete any 1:1 relationship between various (CRM Module) custom modules in the case of Vtiger CRM 7 with the help of a PHP script with all vtlib functions, you simply have to follow some simple steps mentioned above. Must ensure that you have the <a href=\"https:\/\/www.infinitivehost.com\/managed-vtiger-solutions\"><mark style=\"background-color:#8ed1fc\" class=\"has-inline-color\"><strong>best vTiger hosting solutions<\/strong><\/mark><\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1,134 Views To delete or remove a 1:1 relationship between (CRM Module) custom modules in Vtiger CRM 7 using a PHP script with vtlib functions, you need to follow these general steps: Here&#8217;s a sample PHP script demonstrating how to remove a 1:1 relationship between two custom modules, CustomModule1 and CustomModule2: Explanation: Notes: Make sure [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[204],"tags":[],"class_list":["post-8971","post","type-post","status-publish","format-standard","hentry","category-vtiger-solutions"],"_links":{"self":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts\/8971","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/comments?post=8971"}],"version-history":[{"count":2,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts\/8971\/revisions"}],"predecessor-version":[{"id":9037,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/posts\/8971\/revisions\/9037"}],"wp:attachment":[{"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/media?parent=8971"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/categories?post=8971"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.infinitivehost.com\/knowledge-base\/wp-json\/wp\/v2\/tags?post=8971"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}