Adding a panel via javascript in SugarCRM

I’m working on a new feature that requires a panel to be inserted on the edit screen in very specific cases. Since this is for SecuritySuite it must work for all modules; both current and future. Because of this, customizing each module’s view.edit.php is out of the question. The end goal is to allow users who are a member of multiple groups to choose which group(s) should be associated with any newly created record. This used to be the “Use Popup Select” feature but due to the new AjaxUI in SugarCRM this no longer works.

Right below the Assigned To panel and above the buttons is where I’d like to insert the panel:
Where the panel should go

Now here is where the problem comes in. Generally, when you need to show/hide a panel based on a field’s value all you do is create the panel in Studio and then either customize the view.edit.php and view.detail.php or detailviewdefs/editviewdefs.php to spit out javascript to hide the panel based on certain conditions AFTER the parent::process(). If it needs to be tightly coupled to a field’s value then you’d just spit out the appropriate javascript to show/hide all of the appropriate panels. In this case, we don’t necessarily know what modules will ever be created in a given install. Since there are thousands of installs using SecuritySuite on SugarCRM CE for the team functionality it needs to be as forgiving as possible.

The place that allows for this flexibility to customize is the main MVC view.edit.php (include/MVC/View/views/edit.php). Thankfully this module already customizes that file to allow for the custom layout for each team feature. This is not upgrade-safe, of course. There are many changes in SecuritySuite that are not upgrade-safe. It is a necessary evil to ensure that everything is secured properly. Any team solution that claims to be upgrade-safe is doing so at the expense of not truely being secure.

In this specific case the panel should only show if this is to be a newly created record and if the current user is a member of 2 or more groups. Otherwise, it just inherits the single group associated to the user (if the “Inherit from Created By User” is chosen).

On to the code. To insert the panel we are going to do so after the template has been rendered. So we will do this in the display function after the echo.

Yes, some of that code sucks. For example, the functions used to get the group count, etc should be static functions but it’s been around for years and would cripple some folks who use the library so now I’m kind of stuck. If you have suggestions, please fire away.

As of 6.5.0 SugarCRM began shipping with jQuery already included. I’m a fan of jQuery due to the ubiquity of it, ease of use, and ease of finding help. In this case I hand build the panel html then do a preg_replace to remove line breaks as javascript’s support for multiline strings is nil. Once the panel is all set some javascript is outputted with which uses jQuery’s append function to add the panel to the panel container.

Here is the finished result:
The finished product. A panel insert into SugarCRM

Have ideas on how to improve this? I’d love to hear them!



I make high quality solutions at an alarming rate.

Store moved to SugarOutfitters!

Why? Besides being a pain to use for everyone the old store just didn’t provide a good user experience. Moving to SugarOutfitters allows me to provide you with better support and better documentation. This will free me up to continue to support and grow SecuritySuite.

I created SugarOutfitters along with Chad Hutchins to make it easy to “Find quality, proven solutions to enhance your SugarCRM© experience.” We feel what is there now is a good first step to a larger vision of improving that experience. You can get more info from the SugarOutfitters blog. I’d love to hear your feedback on it.
–End Sidebar–

A big thank you is owed to all of you who have used and continue to use SecuritySuite. It has become the most popular teams solution for SugarCRM CE. However, I’m not satisfied with that. There is more that can be added to the suite to make it even more useful to you. Field level access and the ability to filter the list view by groups are two that come to mind. Custom group layouts works for most people who need to hide certain layouts but it doesn’t cover 100% of the cases. If you have some ideas that you’d love to see included make sure to add them as Feature Requests.

To continue its growth and to remove the confusion of having 2 different pricing options only a Yearly Subscription will be offered going forward. It is very important to me that you get a great value for the price and I believe the new price point achieves that while balancing the need to put food on my family’s table (not the same as Latrell Sprewell). I want to give you the best price possible while being able to ensure that this module will be around for a long, long time. With how often the SugarCRM code base changes it is quite time consuming to maintain as there are now 431 files in SecuritySuite. This is a necessity to ensure that your data is locked down and secure.

If you have bought a Yearly Subscription from the old store within the past year your purchase will be honored through the end of its term. You can login and go to your account here to view your subscription order and download all new versions that are released.

Thank you!
-Jason Eggers

Leave a comment


I make high quality solutions at an alarming rate.