SugarCRM — Search for records related to the current record
Posted on Sun 20 April 2014 in Tech
Say you have two modules in Sugar: Animals and Ringmasters and they aren't directly related via a standard relationship but they are related through some convoluted means. Now, imagine if you want to override the SugarCRM search to allow you to search for all Animals indirectly related to a Ringmaster, I've written about how to do something similar recently. Conversely, you want to search for all Animals related to a Ringmaster you're currently viewing. It's not a link that exists in Sugar so you can directly see a Dashlet and you don't want to build anything from scratch so that's going to take effort.
What you could do, is create a link on the action drop-down while viewing the Ringmaster that linked you to a search that would call animals supplying the Ringmaster's id as the argument.
This is based on the previous tutorial I've shared.
- Firstly add a new logic hook in custom/modules/RingMasterModule/logic_hooks.php
php
$hook_array['after_ui_frame'][] = Array(2, 'Custom Ring Master Buttons', 'custom/modules/RingMasterModule/CustomButtons.php
','RingMasterButtons', 'add');
- Then add the custom buttons class in custom/modules/RingMasterModule/CustomButtons.php
```php class RingMasterButtons { function add($bean) { echo $bean; $ringMasterID = $_GET['record']; if(!$ringMasterID) return; // Based on what action we're in, add some buttons! switch ($GLOBALS['app']->controller->action) { case "DetailView": // Add buttons to Detail View
$button_code = <<
EOQ; echo $button_code; break; } } } ```
Quick Repair and Rebuild for good measure. This should add a hidden form that will be called when the user clicks the Ring Master Animals.