Show TOC

Model Instantiation and Data AccessLocate this document in the navigation structure

One OData V4 model instance can only cover one OData V4 service. Accessing OData services of any other version other than OData V4 is not supported. This section describes the creation of a model instance in more detail.

When creating an OData V4 model instance, the only parameter you actually need is a map. This map must contain at least the properties serviceUrl and synchronizationMode. For more information, see the sap.ui.model.odata.v4.ODataModel constructor API documentation in the Demo Kit.

OData V4 model instantiation:

sap.ui.define(["sap/ui/model/odata/v4/ODataModel"], function (ODataModel) {
    var oModel = new ODataModel({
        serviceUrl : "/sap/opu/odata4/IWBEP/V4_SAMPLE/default/IWBEP/V4_GW_SAMPLE_BASIC/0001/",
        synchronizationMode : "None"
    });
});
OData Custom Query Options
An OData service accepts query options placed in the service URL query part, as explained on the URL conventions page OData Version 4.0 Part 2: URL Conventions, 2 URL ComponentsInformation published on non-SAP site. The OData V4 model accepts OData custom query optionsInformation published on non-SAP site only; you must not provide OData system query optionsInformation published on non-SAP site (starting with "$") or OData parameter aliasesInformation published on non-SAP site (starting with "@") at model level.
Note

Note that it's possible to specify certain system query options for OData V4 model bindings. For more information, see Bindings.

OData V4 model instantiation with service URL parameters:

sap.ui.define(["sap/ui/model/odata/v4/ODataModel"], function (ODataModel) {
    var oModel = new ODataModel({
    	serviceUrl : "/sap/opu/odata4/IWBEP/V4_SAMPLE/default/IWBEP/V4_GW_SAMPLE_BASIC/0001/?customParam=foo", 
    	synchronizationMode : "None"
    });
});
Default Groups for Batch Control

The OData V4 model allows you to specify whether or not requests are bundled and sent as a batch request, and when the requests are sent. For more information, see Batch Control.

The parameter groupId specifies the default batch group and defaults to "$auto". You can use the parameter updateGroupId to set a batch group for update requests only. If you do not set this parameter, the groupId will be used.

The following code instantiates a model that bundles all update requests in the batch group "myAppUpdateGroup"; the batch request can then be sent using oModel.submitBatch("myAppUpdateGroup").

OData V4 model with updateGroupId:

sap.ui.define(["sap/ui/model/odata/v4/ODataModel"], function (ODataModel) {
    var oModel = new ODataModel({
        serviceUrl : "/sap/opu/odata4/IWBEP/V4_SAMPLE/default/IWBEP/V4_GW_SAMPLE_BASIC/0001/",
        synchronizationMode : "None",
        updateGroupId : "myAppUpdateGroup"
    });
});
Instantiating an OData V4 Model Using the Descriptor File (manifest.json)

The code sample below shows the parts of a Descriptor for Applications, Components, and Libraries (manifest.json) that are relevant for instantiating an OData V4 model:

{
    "sap.app" : {
        "dataSources" : {
            "default" : {
                "uri" : "/sap/opu/odata4/IWBEP/V4_SAMPLE/default/IWBEP/V4_GW_SAMPLE_BASIC/0001/",
                "type" : "OData",
                "settings" : {
                    "odataVersion" : "4.0"
                }
            }
        }
    },
    "sap.ui5" : {
        "models" : {
            "" : {
                "dataSource" : "default",
                "settings" : {
                    "synchronizationMode" : "None",
                    "updateGroupId" : "myAppUpdateGroup"
                }
            }
        }
    }
}
Data Access

The OData V4 model only supports data access using bindings. It does not provide any direct access to the data. For more information, see Unsupported Superclass Methods and Events.

Language

SAPUI5 uses the concept of a "current language" (see Identifying the Language Code / Locale). This language is automatically propagated to the OData service by the OData V4 model. For this reason, applications must not hard code the language themselves, e.g. they must not specify the "sap-language" URL parameter as a custom query option.