0
votes

I want to create a model and set it as one of the global model in oninit method of component. I have a sap gateway odata service with just an entity type and do NOT have corresponding entityset.

My ui5 project has manifest.json with default model and component.js Is it possible to to create a model using just the metadata.

enter image description here

1

1 Answers

2
votes

When you initialize the model, all you need is the metadata for initializing the SAPUI5 OData model. As long as the metadata is syntactically valid it should not be a problem. The EntitySets are only required when you assign an aggregation to a control using this model.

Update:

Its possible to get the details of the metadata from the model & create a new JSON model with it.

var oModel = new sap.ui.model.odata.ODataModel("http://services.odata.org/V2/OData/OData.svc");
var metaModel = oModel.getMetaModel();

var oEntitySet = metaModel.getODataEntitySet("Products");   //For getting properties of an Entity Set

//For Entity, you may have to provide the service namespace along, in this case ODataDemo
var oEntity = metaModel.getODataEntityType("ODataDemo.Product"); 

The oEntity object will look something like this

oEntity Object

With this you can create a new JSON model as

var oODataJSONModel = new sap.ui.model.json.JSONModel({"Selection" : oEntity.property });

Here is a working example