Namespace: OData

sap. OData

Provides the ability to offline OData services.

The plugin provides the client with the ability to define offline stores for an OData producer. When an offline store is first opened, it will synchronize with the OData producer. OData requests made against this plugin will use the available open offline stores.


The plugin requires that the datajs JavaScript library is included and available to the application. If SAPUI5/OpenUI5 is used, you can call the method `"sap.ui.thirdparty.datajs");` otherwise use a script include for the datajs library.

Custom OData httpclient

A custom datajs OData httpclient is provided by the plugin. This httpclient will resolve requests with the plugin if the service root of the request matches one of the open stores. The httpclient will fallback to using the original OData.defaultHttpClient if the requests service root does not match any of the currently open stores.

Flushing Modifications

The developer must explicitly call the flush method of a store to send modification to the OData producer.

Refreshing Data

The developer must explicitly refresh their stores to get changes from the OData producer. The plugin provides a refresh method that can refresh the whole store or a subset of it.

Tagging Requests

OData requests can be tagged by including the header `OData-Offline-CustomTag`. If the request has an error during flush, the custom tag will be available in the error archive via the CustomTag field.


Sample offline setup code

        var properties = {
            "name": "travel",
            "host": "smpserver",
            "port": 8080,
            "serviceRoot" : "connection_name",
            "definingRequests" : {
                "req1" : "/Travelagency"

        // Create the store.  Need to be online the first time this is created.
        var store = sap.OData.createOfflineStore(properties); {
            // Offline OData calls can now be made against datajs.
        }, function(e) {
            alert("Failed to open store!");


(static) stores :Array.<OfflineStore>

An array of the currently open stores.
  • Array.<OfflineStore>


(static) applyHttpClient()

Replaces the OData.defaultHttpClient with a custom one that uses the SMP OData native APIs. Requests that don't map to an open store will fallback to using the original `OData.defaultHttpClient`.

(static) createOfflineStore(properties) → {sap.OfflineStore}

Creates a new OfflineStore object. The store will be available for offline access only after it is open successfully.
Name Type Description
properties Object Properties used for creating the store object.
Name Type Description
name String Used to uniquely identify a store.
serviceRoot String Identifies the root of an OData service. This can be relative to the host and should be set to a backend connection name from the server.
definingRequests Object.<String, (String|{url: String, retrieveStreams: boolean})> Object that contains the coverage of data as name value pairs. The names are arbitrary and used when performing refreshes with subsets. The values are OData URLs that represent the coverage of data to be managed by the store. For media requests, use the value format { "url" : "Drivers", "retrieveStreams" : true }
host String The host of the server.
port Number The port of the server.
urlSuffix String The URL suffix path to the server.
https Boolean Whether to use HTTP or HTTPS. Default is HTTP.
streamParams String Any additional stream parameters.
customHeaders Object Object that contains the headers to send as name value pairs.
customCookies Object Object that contains the cookies to send as name value pairs.
enableRepeatableRequests Boolean If the OData Producer is able to support repeatable requests then enable use of this.
serverSupportsBind Boolean Specifies whether or not the backend server supports bind operations. Default is true.
A new OfflineStore object.

(static) removeHttpClient()

Removes the custom httpClient if it has been applied.

(static) request(request, successCallback, errorCallback)

Sends a request containing an OData payload to the current open stores. This method can be used for requests that don't go through the datajs http client.
Name Type Description
request Object
Name Type Description
headers Object Object that contains the headers as name value pairs.
requestUri String OData endpoint URI.
method String HTTP method.
body Object Payload of the request.
successCallback sap.OData~requestSuccess Callback function that is called with the response data.
errorCallback sap.OData~requestError Callback function this is called if an error occurs.

Type Definitions


Request error callback.
Name Type Description
error String The error message.


Request success callback that provides the response data.
Name Type Description
response Object
Name Type Description
statusCode Number The status code of the response.
statusText String The status line of the response.
headers Object Object that contains the response headers as name value pairs.
body String The response data.