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:
Managing financial matters has never been this effortless! Seamlessly link records, track payments and request funds on a single click. Install RT SugarStripe and start managing your finances today!
SugarCRM Survey Rocket
SugarCRM Survey Plugin
With Surey Rocket, a SugarCRM survey plugin, you can build surveys that trigger automatically to get real-time feedback from customers. It gives custom survey templates, online polls & more. Moreover, you can use the CRM data using inward and outward piping mechanism.
Find Duplicates BEFORE You Save! Instead of waiting until after you enter a new record's information to know if it's a duplicate, know after the first field if you're working on a duplicate. Say NO to redundant data! Improve your SugarCRM data quality by being prompted of duplicate values while ...
- Show more addons