Integrating and Routing Mobileforce Screens in Sugar

Integrating and Routing Mobileforce Screens in Sugar

Introduction

MobileForce provides several modules (MobileForce_CPQ, MobileForce_FSM, and MobileForce_DSR), that allows one to embed MobileForce screens within SugarCRM. These screens are accessed by special URLs within the SugarCRM instance.

When one goes to one of these URLs within SugarCRM, the MobileForce module will open a SugarCRM screen that is nothing but an iframe displaying a MobileForce screen. The URL determines the MobileForce screen to display.

The URLs supported by the MobileForce modules are as follows:

The URLs that are not of the form https://{sugar-instance-id}/#mfxxx_MobileForce/{query} are legacy URLs implemented before the SugarCRM router was implemented. Given that you can use the SugarCRM router is more powerful and can do anything that the legacy URLs could do, these legacy URLs are deprecated. This document will only cover the SugarCRM router URLs.

Router URL Syntax

All SugarCRM Router URLs are of the form https://{sugar-instance-id}/#mfxxx_MobileForce/{query} where mfxxx is either mfcpq, mffsm, or mfdsr, and {query} is a path that identifies what ADL screen to open as well as what parameters to pass to it.

The {query} part is a list of parameters used to determine which ADL screen to go to and which parameters should be passed to it. These parameters are encoded as path components. This was done to circumvent some limitations with SugarCRM URLs.

The {query} part can be one of the following formats:

The query part is a composition of multiple subcomponents. The following subcomponents mean the following:

ADL Properties

The SugarCRM router supports several ADL properties. By convention, all SugarCRM router properties start with sugarroute-.

These ADL properties can be broken into categories; properties that configure what is passed to the ADL screen, and ADL properties that specify hooks that can be called to customize router behavior.

ADL Screen Properties

ADL screen parameters

The SugarCRM router passes parameters to ADL screens via the params parameter. The params parameter is a standard parameter supported by ADL webui screen. The value of the screens parameter is a JSON object. The fields supported in the JSON object vary based on the ADL screen type.

Here are the fields of the params parameter that are set by the SugarCRM router:

Examples

Here are some examples of ADL screen properties:

<prop key="sugarroute-create-Opportunities-field-account">account_name</prop>
<prop key="sugarroute-create-Opportunities-field-opportunity">id,name</prop>
<prop key="sugarroute-list-Opportunities-field-opportunity_id">id</prop>

Hook Properties

The following ADL properties are supported for SugarCRM routes:

Hook URL Endpoints

One can customize the behavior of a SugarCRM route via hooks. A hook is a HTTP URL.

Hook request parameters

Hooks are invoked using a HTTP POST. The parameters passed to the hook are;

Hook response

Hooks must return a JSON object. This JSON object can have the following parameters:

Mapping of SugarCRM instances to MobileForce accounts.

The SugarCRM router determines the MobileForce account to app to use for a SugarCRM instance from the AccountAppLookup table in the mobileforce.fmaccounts database. Unlike the legacy SugarCRM instance.php script, it does not use the customers/sugarcrm/instance.ini file.

The AccountAppLookup table also has a host column. If this column is not null, the SugarCRM router will redirect to the corresponding SugarCRM router on the server with the given hostname. You can use this hostname field to redirect SugarCRM calls to a different MobileForce deployment, such as our European (apps-eu) or sandbox (apps-sandbox) deployments.

Implementation notes

This section describes the reasons why the SugarCRM router is implemented the way it is.

Why doesn't the SugarCRM route URL accept form fields or object names in its URL?

SugarCRM has several flaws with its module URL syntax. First, SugarCRM does not URL-escape any expanded macro variables in its URLs. Because of this, our module URL will break if you macro expand a variable that has a space or a URL unsafe character such as ampersand (&).

Second, SugarCRM does not properly handle URLs that are longer than 255 characters after macro expansion. Third, SugarCRM uses hash fragments, (e.g., #mfcpq_MobileFore...) for determining the module to call. You cannot include HTTP query parameters after the hash fragment.

Because of these issues, we were forced to implement an indirect means for passing SugarCRM object fields to MobileForce. Rather than passing them directly from SugarCRM via the URL, we instead just pass the object ID in the URL, then read the fields for that object from our router. The fields that need to be read and passed are determined from sugaroute- ADL properties.