Archives For customizations

This article is aimed at beginning to intermediate SugarCRM developers who want to customize views in SugarCRM version 7.

This does not go into detail about all the ins and out of creating custom views, changing metadata and handlebars, etc.  This article merely points out a single technique for extending the JavaScript for an out of the box view to a custom view.  This technique also applies to layouts, but this article will concentrate on views.

This article assumes some knowledge of JavaScript and PHP.

Creating a Custom View From an Out of the Box View

When you create a custom view in SugarCRM 7 you create a subdirectory under

{SugarCRM base dir}/custom/clients/base/views/{new view name}

or

{SugarCRM base dir}/custom/modules/{module name}/clients/base/views/{new view name}

with the various files within it named for the view name.  An out of the box view is one you can find under

{SugarCRM base dir}/clients/base/views/

If you wanted to override one of these out of the box views you would simply create a custom view with the same name.  You can tweak the functionality of an out of the box view by simply copying its source files to your custom view and then customizing them from there.  Let’s say, for example, that you wanted to alter the behavior of the “record” view for a given module.  You can simply copy the out of the box record view locally

cd {SugarCRM base dir}
cp -r clients/base/views/record custom/modules/{module name}/clients/base/views/record

You’ll then need to alter the metadata file (in this case record.php) to reflect the new location

<?php
....
$module_name = "my_ModuleName";
$viewdefs[$module_name]['base']['view']['record'] = array(
    'buttons' => array(
    array(
        'type' => 'button',
        'name' => 'cancel_button',
        'label' => 'LBL_CANCEL_BUTTON_LABEL',
        'css_class' => 'btn-invisible btn-link',
    ),
    ...

If your customizations involve JavaScript changes you’ll want to use the un-minified version of the JavaScript file to work against.  You can copy it from the jssource directory.  In this case you’d run the following command:

cp jssource/src_files/clients/base/views/record/record.js custom/modules/{module name}/clients/base/views/record

At this point you can change the various local files to your heart’s content, and anytime the “record” view is used within your module, your custom view will be used instead.

Like all changes to views and layouts, you’ll need to do a Repair and Rebuild before you see your changes take effect.  When you change the JavaScript file you’ll also need to clear your browser cache.

The Problem With Overriding An Out of the Box View

That’s wonderful until you upgrade.  The problem is that when you upgrade, the out of the box record view might receive changes but your local version of the “record” view won’t.  Over time your custom view will become more and more out of step with the out of the box view.  It could even result in your view breaking eventually.  This isn’t much of a problem for the metadata file since that’s not likely to change much from version to version.  The JavaScript file, however, can change a lot.  It would be nice if there were a way to get the benefit of the improved JavaScript while still keeping a customized version of the view.

Happily this is possible by extending the JavaScript file rather than completely overriding it.

To extend the JavaScript file you simply use JavaScript’s “extendsFrom” functionality.  In our example, to extend the record view the record.js file would look something like this:

({

extendsFrom: 'RecordView',

initialize: function(options) {
    console.log("We are using my customized record view, Yay!");
    this._super('initialize', [options]);
}

})

This JavaScript file will work exactly like the original except that it will now write a message to the JavaScript console whenever the view is used.

The tricky part of this is figuring out what to put in the “extendsFrom” part.  The name follows the form {Module}{Layout|View}.  If you’re extending the JavaScript for a view the {Layout|View} part will, of course, be “View”.  For the {Module} part you take the name of the view and capitalize it.  If the name has dashes in it, remove the dashes and uppercase the following word.  For example, if you were extending the JavaScript for the “filter-module-dropdown” view, the module part would turn into “FilterModuleDropdown” and the entire class to extend would become “FilterModuleDropdownView”.

If you’re ever unsure about what the class may be for the view or layout you’re extending, you can run one of the following commands in the JavaScript console and look at the results.  They should contain the names of all the view and layout classes recognized by the application:

SUGAR.App.view.views;
SUGAR.App.view.layouts;

Calling the “_super” method within an overridden method is important to get the functionality of the parent method.  You can leave it out, but then your local method must do everything the parent method did.

This technique also works if you create a custom view of a different name based on an out of the box view.  There’s no rule saying that what follows “extendsFrom” must match the name of the local view.  It’s merely the JavaScript class you’re inheriting from.

Since you inherit from the parent JavaScript class rather than completely overriding it, and use the _super() method within overridden methods, when you update you’ll automatically get the improved functionality of the base class.

A Quick Caveat

When you extend the JavaScript for a view in this manner there’s always the risk that the changes made in a given update will clash with the customizations you’ve made in your local view.  It depends on the nature of the customizations you choose to make.  There’s no good way to completely guard against that other than never touching the Javascript at all.  Extending a view this way does minimize this risk because you override only what you must rather than the entire JavaScript file.  You should, however, remain aware of the customizations you make and test them thoroughly when you update before going live.

Film Production Planning with SugarCRM In this blog series Epicom engineers share experiences and stories related to projects, assignments and anything else they enjoyed working on. We love what we do and thought we’d share it with you. In this post, Keith Neuendorff tells us about the inspiration behind the Production Manager and how CRM can apply to almost any business. Before I started working for Epicom I was familiar with CRM as a sales force automation tool. Once I

Continue Reading...

Epicom’s engineering intern, Jim Rybarski, is winding down his Spring semester with Epicom. He has completed several internal projects including a project status tracking system, the launch of our customer portal, and a new browser-side password encryption program. We asked Jim to contribute as a guest blogger on our site to share some insight to the work he has done for Epicom. We are breaking his posts up into a weekly mini-series where he will go into detail about the

Continue Reading...

Create and Analyze Surveys in SugarCRM One method of pushing data into your SugarCRM system is through a web-to-lead form. When someone fills out information on your website’s contact form, that information will push through as a lead in Sugar. Web forms can be used for creating leads, but they can also be used to push additional information into the record of an existing contact. Specifically, I’m talking about survey forms. Epicom built a survey module in SugarCRM for customers

Continue Reading...

We asked our engineering intern, Jim Rybarski, to contribute to our blog and give some insight to the internal projects he’s been working on while at Epicom. In this week’s mini-series update, Jim discusses the Project Status Tracking System he developed. The beginning stages of taking on a new client can be very tedious and time consuming. We asked Jim to develop a system that would make this a smoother process. Here is what Jim had to say. Taking on a

Continue Reading...

In this short training session, Epicom’s software engineer Tommy Wiebell discusses dashlets and dashlet tabs in SugarCRM. Because dashlets are the first visual users are exposed to when logging into the system, it is important that they are customized accordingly. Layout is the first step in customizing your dashlet tabs. You are given three layout options, which Tommy goes over in detail. “Everything is customizable per user, so whatever you select here will not be pushed out to any other

Continue Reading...

Managing more than the email campaign. Campaigns are the theme and big picture of a marketer’s tactical efforts. It’s what email messages, blog posts, promotions, webcasts, conferences, advertising, and lead source are all tied to. One reason for a campaign is to have synergy among different marketing tactics so that each support one another in order to have a greater impact. Another reason for a campaign is to better report ROI. SugarCRM has a Campaigns module for reporting, tracking email

Continue Reading...