Sugar 7.5 Metadata Diving for Smarter Integrations

Matthew Marum —  April 20, 2015 — 1 Comment

For Sugar 7.7 and later versions, you can access metadata from within the Sidecar clients using 

SUGAR.App.metadata.get()

Many Sugar Developers are looking to build intelligent API integrations with Sugar that goes beyond Create-Read-Update-Delete (CRUD) operations.  The key to building robust and intelligent API integrations with Sugar is held within the Sugar Metadata.

Sometime it is interesting to understand what dependent dropdowns exist on any given Sugar module.  A common use case would be to display appropriate UI with properly populated drop down lists to end users of an integration with Sugar 7.

Example Dependent Dropdown

Example Dependent Dropdown

If you don’t have the dependent dropdown formula then you are stuck guessing at what options are available or showing the user the full list of options when only a subset of them are valid choices.  The key for addressing these user experience concerns and for anybody else wanting to take their Sugar API integration to the next level is the Sugar Metadata API.

If you are familiar with Sugar 7 then you probably know that we use the v10 REST API to drive the Sidecar framework used in our web, mobile, and portal clients.  Sugar Logic formulas are configured in Sugar Metadata which means the Metadata API is how the Sidecar framework is made aware of them.

Example dependent dropdown within Sidecar

Example dependent dropdown within Sidecar

If you are building a Sidecar client then Sugar Logic gets handled for you automatically – but otherwise you can mine the metadata to find the tools you need.

For convenience, you can browse the entire Sugar metadata cache for any user using your browser’s dev tools (such as Chrome Dev Tools used in example below).  Just log into Sugar 7 as your target user, open your javascript console, and run the commands below.  This will return the current metadata payload that was retrieved from server via Metadata API.

SUGAR.App.metadata._dev_data; // replace _dev_data with get() in Sugar 7.7 and later

In this example, the full options list of display values used is available within app_list_strings.car_list.

SUGAR.App.metadata._dev_data.app_list_strings.car_list;

This can be compared with the dependent dropdown formula found in the Opportunity Record view metadata.  Sugar Logic defines dependencies between fields that affects their presentation to end users.  So you’ll find this information mixed into the View metadata in the dependencies hash.

SUGAR.App.metadata._dev_data.modules.Opportunities.views.record.meta.dependencies;
Example dependency console log output

Example dependency console log output

This should give them all the information they need to intelligently work with this dependent dropdown field.  Now they can decide how they want to handle these in their integration.

A quick note about programming against Metadata API

The Sugar metadata payload is pretty large so you’ll want to cache it as much as possible.  It’s a good idea to only retrieve the metadata for modules you care about to limit the size of the request.  You should track the metadata hash value which can be used to reload metadata only when it changes.  Again, if your code is running within Sugar 7 (and therefore using the Sidecar framework) then metadata is refreshed automatically as needed – so you can always assume the metadata you find there is up to date.

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.

One response to Sugar 7.5 Metadata Diving for Smarter Integrations

  1. 

    Hi Matt Marum,I created some dependent dropdown in calls module that is working fine in 7.6.1.0 but when we upgrade sugar dependent dropdown is not working in 7.7
    we are getting error “Uncaught ReferenceError: slContext is not defined at child.getApplicableDeps

    Please help me this scenario

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