Using server side changes to customize SugarCRM Mobile

Matthew Marum —  June 11, 2015 — 6 Comments

If you were at UnCon in April 2015 then you know that one of our hottest topics was plans for a SugarCRM Mobile SDK.  Since mobile devices and mobile use cases are such a key part of what Customer Relationship Management and Customer Experience is today and will be in the future, we are planning to enhance the SugarCRM Mobile development platform available to Sugar Developers.  You can follow the blog here for updates on that as they become available in the future.

However, there are already many different ways that developers can customize the behavior of the existing SugarCRM Mobile application today.  That will be the focus of today’s post.  In fact, you can drastically customize the behavior of the SugarCRM Mobile application without the hassle of having to distribute any custom code or apps to end-user Mobile devices.  All these techniques listed below involve only Sugar 7 server side code and metadata customizations.

Metadata based Customizations

As every Sugar Developer should be well aware, Sugar metadata serves as the architectural backbone of the Sugar 7 platform.  All Sugar 7 clients, including the SugarCRM Mobile application, are driven via Sugar metadata which means changes in Sugar metadata can already be used to reflect changes in appearance and behavior of the Mobile client without having to write a line of JavaScript.

Mobile Layouts & Sugar Logic

Sugar Logic allows you to utilize expressions and actions to establish dependencies between fields within a Sugar module.  It is already a best practice to utilize Sugar Logic where possible since it is applied consistently across the application both client and server-side.  So always remember that Sugar Logic works in SugarCRM Mobile too.

For example, if you want to display custom information or messages to a user on Mobile, you could add a read-only dependent field to Mobile Layouts to deliver it.

Try this example, all you need to do is create a calculated field in Sugar Studio and configure the formula as seen below.

Sugar Logic messages on SugarCRM Mobile

Sugar Logic messages on SugarCRM Mobile

API based Customizations

Similar to Sugar metadata, the Sugar 7 REST API serves as the transport backbone for the Sugar 7 platform.  All Sugar 7 clients, including the SugarCRM Mobile application, utilize the same APIs to communicate with Sugar server.  This makes the APIs the ideal critical point to intercept messages that come from the Mobile client.

API Logic Hooks

Most Sugar Developers are familiar with the Module Logic Hooks that are available in the system.  For example, whenever a record gets saved to the server in Sugar the before_save and after_save logic hooks are triggered.  It doesn’t matter that these requests originated from the Mobile client, the base Sugar 7 web client, the Sugar portal client, or some other web services integration.

However, each user session (and therefore each API request) does have a platform identifier associated with it.  This is gets associated with the session when the user logged in.  For requests coming from the SugarCRM Mobile application, this platform identifier is always “mobile”.  With this in mind, it’s possible to intercept each API call from a Mobile client session via one or more API Logic Hooks in order to do something special in those cases.  In the example below, we just write information about the request to the sugarcrm.log file.

To try this example, copy the following two files to custom/MobileApiLogicHook.php and  custom/Extension/application/Ext/LogicHooks/after_routing_mobile.php.

Thu Jun 11 13:23:52 2015 [15726][-none-][FATAL] Mobile request to ["oauth2","token"]
Thu Jun 11 13:23:53 2015 [15726][1][FATAL] Mobile request to ["me"]
Thu Jun 11 13:23:53 2015 [15635][1][FATAL] Mobile request to ["metadata"]
Thu Jun 11 13:23:56 2015 [15635][1][FATAL] Mobile request to ["ping","whattimeisit"]
Thu Jun 11 13:23:56 2015 [15635][1][FATAL] Mobile request to ["ping"]
Thu Jun 11 13:23:57 2015 [15726][1][FATAL] Mobile request to ["Dashboards"]
Thu Jun 11 13:23:57 2015 [15635][1][FATAL] Mobile request to ["Users","filter","count"]
Thu Jun 11 13:23:57 2015 [15726][1][FATAL] Mobile request to ["bulk"]
Thu Jun 11 13:23:57 2015 [15726][1][FATAL] Mobile request to ["Dashboards","f3b37ac6-60f2-0606-18a0-55773d752273"]
Thu Jun 11 13:23:57 2015 [15726][1][FATAL] Mobile request to ["Dashboards","be9896e2-cddc-f88c-c161-55773d8013ed"]
...

Override API endpoints for Mobile platform

Or you can define a custom API endpoints for the Mobile platform to handle specific requests entirely differently for the Mobile clients than you would for other clients.  In the example below, we have modified the OAuth 2 API that is used for authentication to restrict mobile device access to Sugar 7.  This restriction could be based upon the role of the current user, whether Sugar 7 is being accessed via the native iOS, Android app or a mobile device’s web browser.  It is even possible to check the kind of device being used (tablet, phone, or PC).

To try this example, add the following file to custom/clients/mobile/api/RestrictedOAuth2MobileApi.php

Failed login on SugarCRM Mobile

Failed login on SugarCRM Mobile

Metadata & API based Customizations

You can also combine the techniques described above to create more sophisticated SugarCRM Mobile customizations.

Lightweight Custom Modules

While SugarCRM Mobile does not yet support custom views, it does support the addition of new custom modules.  So if you already have an existing Custom Module that you want to display in the Mobile client then consider creating an additional simplified Custom Module that is a facade for your existing custom module or even one of Sugar 7’s BWC modules.  You can then use a Sugar Job to synchronize key data into your mobile Custom Module.   Or (as seen below) you can modify the Mobile Module’s API endpoints to pull data from other Modules or sources in real time.

To try this example, you will need to create a test_MobileContracts custom module using Module Builder, define the layouts, fields, metadata, etc, for it and then enable it for Mobile via the Admin panel.  Then add the following file to modules/test_MobileContracts/clients/mobile/api/MobileContractsMobileFilterApi.php

Example of custom module pulling Contract records into SugarCRM Mobile

Example of custom module pulling Contract records into SugarCRM Mobile

Matthew Marum

Posts

Matt is the Director of Developer Advocacy for SugarCRM. Previously he was an Engineer on Sugar 7 and a Solutions Architect for the OEM program. He is also an avid trail runner, Boston Marathon qualifier and a karaoke aficionado.

6 responses to Using server side changes to customize SugarCRM Mobile

  1. 

    Does your Mobile App work with Good MDM?
    Is it possible to customize the Mobile App with Good SDK?
    https://www1.good.com/secure-mobility-solution/mobile-application-containerization

    • 

      While the Mobile app could be integrated with the Good SDK. It is not today.

      We will be offering the capability for app wrapping binary files in the very near future. We are happy to discuss this with you privately if you have a customer with this request.

  2. 

    On the mobile app, are the sub-panels of a module rearrange-able as they are in the web app? And if so, can they be ordered to match the order of the sub-panels in the web app?

  3. 

    On the mobile app, are the sub-panels of a module rearrange-able as they are in the web app by individual? And if so, can the sub-panels in the mobile app be made to match the order of the web app?

    • 
      Matthew Marum May 25, 2016 at 12:28 pm

      They cannot be repositioned by an end user. But the order can be changed by adjusting the order that subpanels appear in Sugar metadata. This could be accomplished with a PHP metadata customization on the subpanel layout on the server side.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s