Today's guest post comes from Andrew Copley, an experienced developer who knows the ins-and-outs of SugarCRM. What we love about this post, besides the obviously cool functionality, is the high level concept of safely customizing the core functionality in a novel way. This translates into a solution that can be easily mass distributed via add-ons.
One of the more common requests I receive from my clients is default searches based on roles and users for ListViews. Of course you can set up predefined searches through the advanced Search panel, but often clients want the convenience of the search already implemented on retrieving the List. A relatively straightforward way is to use a logic_hook on the 'after_login' event to force a search on to the preferences for the module.
Suppose we wish to retrieve only those contacts which belong to a particular account 'ACME Inc.'.
1. If there isnt already a logic_hook.php file, create one in the 'custom/modules/Users' directory and add an entry:
<?php | |
$hook_array['after_login'][] = Array(0, 'Default_Search', 'custom/modules/Users/defaultSearch.php','defaultSearch', 'filterList'); |
2. The second part is to create the file defaultSearch.php in the same directory, defining the class 'defaultSearch' with the function filterList. We also need to include the StoreQuery class which will be used to force the query onto the list.
<?php | |
include('modules/MySettings/StoreQuery.php'); | |
class defaultSearch | |
{ | |
function filterList(&$bean, $event, $arguments) | |
{ | |
global $current_user, $sugar_config; | |
// create instance of StoreQuery | |
$squery= new StoreQuery(); | |
//specify query and save | |
$squery->query=array('account_name_basic'=>'ACME Inc', 'module'=>'Contacts','searchFormTab'=>'basic_search','query'=>'true','action'=>'index'); | |
$squery->SaveQuery('Contacts'); | |
} | |
} |
Of course, this can be augmented with a conditional statement of user or role, for example. For Advanced searches, you need to replace 'basic' with 'advanced' and multiple list values use an array: e.g. 'assigned_user_id_basic'=>array('1','
One of the great advantages of using this method is that if the user changes the search and logs out, on logging in again, the original predefined search is restored.
-
Keep in Touch (KIT) for Sugar
FEATUREDIs keeping track of customer outreach a struggle? With the "Keep In Touch" add-on, you can set how often you want to check in with your target prospects, leads or contacts, such as a call ev... -
DocProStar
FEATUREDDocProStar transforms your inbound documents and emails into actionable data, directly within SugarCRM. Using machine learning and AI, we automate digital mailroom, email triage, and financial process... -
Maintenance Mode Module
Need to turn off access to SugarCRM temporarily while you upgrade your servers? Doing a big code deploy and want to avoid any issues with users? Simply turn on a Maintenance Mode message which disable... - Show more addons