Preface
When you are using a relate field to search for records, you have an arrow button that opens a popup view that allows you to select the record that will be used to filter results.
After selecting the record, the popup screen closes and the selected record will appear in the search field.
So far so good… but what happens when in the opened popup you wish to search for a record and use a relate field in the popup’s search to narrow the list of results?
Unfortunately SugarCRM currently doesn’t support this behavior of filling the relate field in popups as they do in regular list views.
The Problem
The problem lies in the callback function of the relate field’s search button.
When the popup is built, the “form_name” in the return callback is set to “search_form” – which works fine for regular list views search forms but not for popups search forms.
For popups search forms the returned “form_name” should be “popup_query_form”.
The solution
Please note that this fix is not upgrade safe.
- go to the file: /include/SugarFields/Fields/Relate/SugarFieldRelate.php
- in the getSearchViewSmarty function you will need to add an else statement just before the last else statement that builds the $popup_request_data array.
eventually the if-else block should look as appear in the image below. - Repair and open the popup again for the changes to take effect and voilà!