Just like many of you, we wear a number of hats with one of them being developers. As part of that, we sometimes run into somewhat unique issues. Although this post is a slight deviation from the main line of dev tips, we feel it is something worth highlighting as it deals with how to handle unexpected issues when developing on SugarCRM.
TL;DR - If you are echoing out data to the client in a before_retrieve or after_retrieve logic hook, navigating via AjaxUI will break when attempting to go to the Detail View of any module that has a registered before_retrieve or after_retrieve logic hook. To get around this, use an after_ui_footer or after_ui_frame logic hook or echo your extra data elsewhere.
Recently while working on a client issue, I ran across a problem that kept occurring when trying to access a Contact's detail view. It would only fail when the page was being loaded with AjaxUI. It would error out with something similar to the following:
After examining the results of the ajax request to pull a contact's detail view, I noticed that the response was not valid json, preventing the client from properly dealing with the response. There was extra markup being added to the response. After searching for the contents of the extra markup in the codebase, I realized it was originating from an after_retrieve logic hook. There were multiple echo statements outputting data to the screen directly from the logic hook.
When Sugar introduced AjaxUI in SugarCRM 6.3, they did a decent job at handling most cases like this so that pre-6.3 customizations would still work with the AjaxUI changes. After trying to echo contents to the screen from other logic hooks (process_record, after_footer_ui, etc.), Sugar would work just fine. It would process the ajax request perfectly. It was only the detail views of *_retrieve hooks that have echo's that would break navigating with AjaxUI.
After digging deeper, it appears that the after_retrieve logic hook gets called for all modules deep into the application loading process of Sugar before an ob_start() call is made to start capturing anything echo'd. Because of this, as soon as you issue an echo in the logic hook, it gets sent to the client outside of the nicely formatted json response it's expecting.
If you'd like to replicate the issue for yourself, add an after_retrieve logic hook to a module and drop the following script in your /custom/modules/<module>/ folder. I'm using the Contacts module for the example and tested using SugarCRM CE 6.5.5.
Having said all that, to solve the issue, I first attempted to run change from an after_retrieve hook to a process_record logic hook, but for whatever reason, process_record doesn't fire when you load a Detail View although the docs say it's suppose to.
The solution that ended up working was going with an after_ui_frame logic hook and explicitly catching the Detail View case as follows:
Scan Identical Leads
Have newly created leads? Processing imported leads from one or more sources? Quickly identify if there is already an existing lead by setting up your predefined parameters. Any possible duplicates will be highlighted and noted when viewing a given lead.
Sage 100 ERP (MAS 200 SQL) Enterprise
All of the power of Sage Professional, but with the additional capabilities to sync multiple Sage 100 ERP companies to one instance of Sugar, supports all editions of Sage 100 ERP, and includes the ability to map standard and custom fields between Sugar and Sage 100 ERP. Unlimited 9-5 PST support fo...
TapCRM - Mobile CRM App for SugarCRM
Best SugarCRM Mobile App
Enable your teams to access real-time CRM data on the go with SugarCRM mobile app. TapCRM, created for SugarCRM, comes with exclusive features like Live Tracking. Get an overview of your business life cycle with conversion rates, sales performance, and monthly outcom...
- Show more addons