<div>Hi !</div><div><br></div>I have a crm installation where the module Accounts is related to itself by a related list.<div><br></div><div>It works very well and it&#39;s easy to manage a list of accounts related to any specific account.</div>

<div><br></div><div>The problem is when we want to remove an account Z from the RelatedList of account A.</div><div><br></div><div>Instead of just unlinking the account Z, Vtiger sends it to trash (deletes it).</div><div>

<br></div><div>This is caused by the function DeleteEntity in /include/utils/Utils.php</div><div><br></div><div><br></div><div><div>function DeleteEntity($module,$return_module,$focus,$record,$return_id) {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>global $log;<span class="Apple-tab-span" style="white-space:pre">        </span></div>

<div><span class="Apple-tab-span" style="white-space:pre">        </span>$log-&gt;debug(&quot;Entering DeleteEntity method ($module, $return_module, $record, $return_id)&quot;);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div>

<div><span class="Apple-tab-span" style="white-space:pre">        </span>if ($module != $return_module &amp;&amp; !empty($return_module) &amp;&amp; !empty($return_id)) {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>$focus-&gt;unlinkRelationship($record, $return_module, $return_id);</div>

<div><span class="Apple-tab-span" style="white-space:pre">        </span>} else {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>$focus-&gt;trash($module, $record);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div>

<div><span class="Apple-tab-span" style="white-space:pre">        </span>$log-&gt;debug(&quot;Exiting DeleteEntity method ...&quot;);</div><div>}</div></div><div><br></div><div>It is a smart function but since $module == $return_module in our case, this function does not &quot;unlinkRelationship&quot; but Trashes the $record.</div>

<div><br></div><div><meta http-equiv="content-type" content="text/html; charset=utf-8"><div>So far I&#39;ve found no workaround since there is no trigger available to use an event when deleting an entity. So I ended up modifiying the function. But this is of course not a future proof (I mean update proof) solution as I&#39;ll have to do it every time a new version of Vtiger is released.</div>

</div><div><br></div><div>My question :</div><div>Is there any specific reason to have this test here ( $module != $return_module ) ?</div><div><br></div><div>I think it was added to test if the deletion is occuring within a RelatedList (in most cases in a related list $module != $return_module)</div>

<div><br></div><div>I have another suggestion :</div><div>We could test instead $_REQUEST[&#39;return_action&#39;], if it contains &quot;CallRelatedList&quot; then we are in a RelatedList and we can unlink instead of sending to trash.</div>

<div><br></div><div>Here is my modified function :</div><div><br></div><div><div>function DeleteEntity($module,$return_module,$focus,$record,$return_id) {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>global $log;<span class="Apple-tab-span" style="white-space:pre">        </span></div>

<div><span class="Apple-tab-span" style="white-space:pre">        </span>$log-&gt;debug(&quot;Entering DeleteEntity method ($module, $return_module, $record, $return_id)&quot;);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div>

<div><span class="Apple-tab-span" style="white-space:pre">        </span>if (isset($_REQUEST[&#39;return_action&#39;]){</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>$return_action = $_REQUEST[&#39;return_action&#39;];</div>

<div><span class="Apple-tab-span" style="white-space:pre">        </span>} else {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>$return_action = &quot;&quot;;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div>

<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if ($return_action == &quot;CallRelatedList&quot; &amp;&amp; !empty($return_module) &amp;&amp; !empty($return_id)) {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>$focus-&gt;unlinkRelationship($record, $return_module, $return_id);</div>

<div><span class="Apple-tab-span" style="white-space:pre">        </span>} else {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>$focus-&gt;trash($module, $record);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div>

<div><span class="Apple-tab-span" style="white-space:pre">        </span>$log-&gt;debug(&quot;Exiting DeleteEntity method ...&quot;);</div><div>}</div></div><div><br></div><div>What do you guys think ?</div><div><br></div><meta http-equiv="content-type" content="text/html; charset=utf-8"><div>

David V.<br>
</div>