Here are two free plug-in tools that make it painless for Sugar 7 users to get a quick glimpse into critical history items.

Continue Reading...

If you want to use namespaces following the PSR-0 standard for your custom code, it is now possible with the SugarAutoLoader in sugar7. Now you don’t have to insert require statements all over the place.

require_once('include/utils/autoloader.php');

SugarAutoLoader::addNamespace('Fbsg\\', 'custom/include/Fbsg');

Sugar’s autoloader will now map requests for the class Fbsg\Example\Test to the file “custom/include/Fbsg/Example/Test.php”.

Post From Faye Business Systems Group Director of Development Matthew Strickland

Contact Jesse Heller

When you work with something everyday, eliminating tedious and repetitive tasks not only improves your productivity but also helps your sanity. With Sugar, there are certain things we as developers are constantly doing; in some cases, over and over again. How many times have you run quick repair and rebuild?

Luckily, we program things. We write scripts that make our lives in that moment a tad bit easier. But it’s easy to lose track of these things; we might even write the same tool over and over again.

In this series of posts, we’re going to build a command line utility tool whose only purpose is to make life more beautiful. If you’ve ever used the laravel framework, you are familiar with the “artisan” tool which is built with the symfony console component. We are going to do the same thing.

The general idea here is to be able to call commands like these:

$ sugarcli admin:repair
$ sugarcli manifest:validate

Let’s get started.

We are going to be using symfony console composer, so if you aren’t familiar be sure to read-up on it. The first thing, we need to do is pull in our symfony console dependency in composer.json.

{
    "require": {
        "symfony/console": "v2.4.4"
    },

    "autoload": {
        "psr-4": {
            "Fbsg\\": "src"
        }
    }
}
$ composer install

Notice that we are using psr-4 for are auto-loading our classes, as we will be using psr compliant namespaces.
Now that we have our dependencies installed to the vendor folder, we are ready to start.

In the next post, we’ll be building the quick repair/rebuild command.

You can view the github repository here.

Post From Faye Business Systems Group Director of Development Matthew Strickland

Contact Jesse Heller

 

Editor’s Note: This blog post comes from Bill Convis of SierraCRM, and talks about how his team worked with our top notch engineering team to find a way to add action menu items across multiple modules. Big thanks to Bill for the writeup, and Peter DeMartini of SierraCRM, and David Wheeler of SugarCRM for helping form the solution.

With the release of SugarCRM 7 came new challenges and opportunities for SugarCRM technology partners. An entirely new paradigm was offered for solution providers to add new features to the power of SugarCRM. Process Manager Enterprise (PM) from SierraCRM, a workflow solution that augments SugarCRM’s existing workflow, was being updated to take advantage of the new architecture.

One of the features to be added to the new release of PM was the ability to see all the processes for a single object. Our intent was to show both processes that had been completed and process that were currently active.

After reviewing the options, a decision was made to add an “action item” to a record view to display a drawer with a listing view of the processes for that record.

We approached John Mertic at SugarCRM and asked him if there was an extensible framework for action buttons, as we wanted to build a solution that was both upgrade safe and would be global across all modules. He suggested we meet with the engineers at SugarCon.

At the SugarCon 2014 conference in San Francisco, Sierra’s senior developer, Peter DeMartini, met up with SugarCRM Engineer David Wheeler at one of the hacker sessions.

David suggested an approach in which we would keep the ./custom/clients/base/views/record/record.php which would define the button for every record. Then a new file that would enable us to include the javascript code behind the button click event in every module in SugarCRM that displays the record view.

This new file would be ./custom/clients/base/layouts/record/record.php.

In record.php we injected our custom layout, pm-record-logic, into the baseline record view. This pm-record-logic layout was the key to ensure that custom javascript code was guaranteed to be present for the modules record view and this javascript would be available on the click event of the new action button.

The final file that was created with the help from David (this was the most important piece for us) was the pm-record-logic.js file. David suggested we extend the initialize function , call the _super method and then bind our code to the click event for the button created above. The code snippet is:

We will now present the code in its entirety with instructions for other solution providers to accomplish the same thing:

The first file is record.php and lives in ./custom/clients/base/views/record/record.php

This file adds the action button to the action menu. The ‘name’ => ‘pm_record_reports’ will map to a file ./custom/clients/base/views/pm-record-logic/pm-record-logic.js with an initialize function that will set this buttons name to a click event function.

The next file is also named record.php and lives in ./custom/clients/base/layouts/record/record.php

What is key in this file is the ‘layout’ => ‘pm-record-logic’. Which allows us to inject our custom view into every record view.

Our first file is:

./custom/clients/base/layouts/pm-record-logic/pm-record-logic.php

And our handle bars file ./custom/clients/base/views/pm-record-logic/pm-record-logic.hbs

And finally our pm-record-logic.js file which makes the api call to Process Manager to retrieve all the processes for the given object:

./custom/clients/base/views/pm-record-logic/pm-record-logic.js

The remaining files used in this customization are the view and layouts for the actual data returned by Process Manager to be shown in the drawer.

What was key to this customization, and what we learned from the outstanding support from John and David, was the ability to be able to guarantee that our new action button click event function in javascript would be placed on the action menu for most modules (excluding Leads) and that we had confidence that the javascript functions on the click event would also be present.

During the Sugar 7 Developer training sessions, the attendees often asked for more code samples to get up to speed writing dashlets. This blog provides a good template that could be used when writing a dashlet that will pull data from an external source.

Quick start
The dashlet is available for free on Github https://github.com/tortugacrm/sugar7_football_wc2014_dashlet
This code is published under the GPL 3 license.
For a quick installation in your Sugar 7 instance, please follow the guidances in §Installation.
The dashlet comes in English, French, German, Swedish and Russian.

Football WC14 dashlet

Introduction
This blog post is a straightforward example how to consume an external service and render the data into a dashlet. The service will be the World Cup in JSON! http://worldcup.sfg.io
This is a free REST API that returns the scores for the games played the current day or the scores for your favorite team.

JSON example:
http://worldcup.sfg.io/matches/today

Remark: if the response is empty, there is no match scheduled for the day. Please try the other call: http://worldcup.sfg.io/matches/country?fifa_code=USA

[{
    "match_number": 45,
    "location": "Arena Pernambuco",
    "datetime": "2014-06-26T13:00:00.000-03:00",
    "status": "in progress",
    "home_team": {
        "country": "USA",
        "code": "USA",
        "goals": 0
    },
    "away_team": {
        "country": "Germany",
        "code": "GER",
        "goals": 0
    },
    "winner": null,
},
ETC...

It looks like another News dashlet? Not at all! If you ever tweak the out of the box News dashlet, you probably noticed that the data source was tough to change. Why? The reason is browser security: a default behavior prevents JavaScript cross-scripting. In short, JavaScript can only call services located on the same server unless they are over https.

Assuming you start with a clone of the News dashlet, the JQuery call to the World Cup service will return a 401 error (unauthorized). How to fix this? All you have is to make the call with a PHP script located on the same web server. The best practice will be extending Sugar REST services by adding a custom endpoint. Then, your JavaScript controller will call the service that will call the external World Cup service and then will receive the data in a JSON format and will send it back to the JS controller.

The code

Edit: 30th June 12:45AM CET. blog & github had been updated. The web service call is made through a custom endpoint.

Now let’s have a look to the code.

The PHP script that calls the service. We implement two calls. The first to retrieve the games for the day, the other one to return all the games for a specific team. If the first call does not return any data, it is because no game is scheduled on that day.

You might already be familiar with the function call_service (it was already published on this blog). I added one parameter at the end that lets the user decide if he wants to receive a JSON string or the data in a structured PHP array.

And a last important remark: the name of the class and the php file has to be the same. I recommend to end this name with “Api”.

./custom/clients/base/api/WorldCup14Api.php

Now the dashlet:
1) The metadata
./worldcup14/worldcup14.php

2) The controller

./worldcup14/worldcup14.js

Easy to understand. the loadData function builds the parameters to provide to the PHP script depending the settings (shall we show today’s matches live scores or my favorite team’s scores?)
Then, this mysterious loop modifies on the fly the date value in order to be shown according to the user’s timezone, based on his settings in Sugar:

$.each(data, function (idx, obj) {
    obj.datetime = formatDateUser(obj.datetime);
});

Note these two functions:
– app.api.buildURL will build the url to call our custom web service.
– app.api.call will call our custom web service.

3) The Handlebar template
./worldcup14/worldcup14.hbs

Remark: as the JSON data do not come with item names, the loop is built on “this” (good to know).

4) The language files
./language.worldcup14/en_us.lang.php

5) And finally the manifest.php
./manifest.php

Installation

This section describes how to install the dashlet. It does not required any technical knowledge. However, please be aware that you will follow the exact steps.

1) Download the module (Zip file) from the Github repository
https://github.com/tortugacrm/sugar7_football_wc2014_dashlet
Click on the ‘Download ZIP‘ button located on the bottom right.
2) Log in your Sugar 7 instance as the admin.
3) Go to the menu located next to the profile picture on the top right. Click on ‘Admin’.
4) Scroll down to the 5th section called ‘Developer Tools’. Click on ’Module Loader’.
5) In the lower section of the page, click on the ‘Choose file’ button, select the wc14.zip archive included in the file you downloaded during step 1. Click on ‘Upload’.
6) Now the module is in the list below. Click on the install button.
7) Accept the license.
8) Wait for the browser to complete the installation. This step might take a couple of minutes, be patient. For some unknown reasons, some instances might finish the installation with a blank screen. It should not, but it’s ok. The installation is finished when your browser stops loading the page.
9) On the top bar, click on ‘Administration
10) Scroll down to the 3rd section called ‘System’. Click on ’Repair’.
11) Click on ‘Quick Repair and Rebuild
12) Wait for the browser to complete the repair. The repair is finished when your browser stops loading the page.
13) Log out
14) Clear your browser cache
15) Log in as Jim
16) Edit the Dashboard
17) Select the area where you want to see you dashlet. Click on the Plus image
18) Chose the ‘Football’ dashlet in the list. You might want to preview it clicking on the preview button (with the eye).
19) Configure the dashlet: chose to view the games for the current day or your fav team’s games
20) Save the dashboard
21) Be a happy user of the Football dashlet!

Acknowledgements
I would like to thank my colleagues: Abhijeet who found out the World Cup Json web site, Harald for reviewing the code, Alena, Anki, Evi for the translations.
Special thank to Jeff Bickart who suggested that I added a custom endpoint in order to provide the best practices in this tutorial.

I had this question come from a partner this week…

Users can’t maintain their two sessions of Sugar (One via the REST API, and the other their Sugar Instance) at the same time. Signing in to either one will always result to the session expiration of the other one

This is mostly because the Sugar 7 uses the same REST API to power all the new Sugar UX components, so if you need to let the API know you aren’t coming from the desktop client. The way to do this in as a part of the /oauth2/token call, changing the ‘platform’ parameter as shown below to something other than ‘base’, ‘mobile’, or ‘portal’…

There was a discussion recently in Andrea Ayer’s Sugar Adminstration Essentials class about previous layouts are stored in Studio when changing how a screen looks. You can access it on an View edit screen by clicking ‘View History’…

Screen Shot 2014-06-18 at 4.45.54 PM

 

The specific question came up of how many previous layouts are saved. Here’s the answer…

  • By default, the past 50 layouts are saved
  • You can change this by setting the config variable $sugar_config[‘studio_max_history’]
  • Setting $sugar_config[‘studio_max_history’] to 0 will enable saving all previous layouts