AnsweredAssumed Answered

In Sugar, how to customize popup search to display records depending on the selection of another relate field in Many-to-Many relationship scenario?

Question asked by Sohan Tirpude on Oct 13, 2016

I have two modules, consider A & B. In between them, there is many-to-many relationship. Now, there is another module, consider C. There is One-to-Many between A & C and B & C. Now while on editview of C module, both relate fields of module A & module B are present.

Now, after selecting any record from module A, while selecting records from module B, I want to show only those records which are related to the selected record of module A.

Now, I have came across these links, where they provided solution in the scenario of having One-to-Many relationship between these modules.

How can I customize the popup search to display possibilities depending on the parent page?

SugarCRM: relate field passing default values to pop-up select form

Wherein "One-to-Many" scenario, we can achieve the same by adding following code to editviewdefs.php file of targeted module, like this:

'displayParams' => array( 
    'initial_filter' => '&contact_name_advanced="+encodeURIComponent(document.getElementById("contact_name").value)+"',

OR like this:

'displayParams' => array ( 
    'initial_filter' => '&account_name={$fields.account_name.value}',

But neither these posts mentioned any solution for "Many-to-Many" scenario nor I found any such post.

I came across another post:

SugarCRM Custom Query in popup list

where it suggested, along with above solution, to add few lines of code in popdefs.php file. But it is not wise option, as this popdefs.php file automatically generates by SugarCRM.

I came across few more posts:

How to Override view.popup in sugar CE 6.5.18

How I can customize query in view.popup in SugarCRM

where it suggested to customize the sql queries inside the popupview (view.popup.php) in SugarCRM. I tried that, but still I found no success. Kindly help. Thanks.