cancel
Showing results for 
Search instead for 
Did you mean: 

CreateEntry method

former_member512938
Participant
0 Kudos

Hello dear Experts,

I am confused, but I can't achieve what seems to be a simple task. Here are my requirements :

I am currently designing a simple "create" application using SAPUI5 against NW Gateway oData, through SAP Cloud Network. This application should be a single page, reachable via a simple link.

My starting point is the basic "Worklist" template, which seems to be the most comprehensive template to start with... That said, it is far from beeing that intuitive... (no offense :)).

I am trying to use the "createEntry()" method which will, as far as I understand, create me an "empty" entity, or "temporary object" based upon my oData collection.

My app setting is based upon the manifest.json file.

My component.js is no more that the template-generated one :

In my init() method of my controller, i call this :

this.getRouter().getRoute("create").attachPatternMatched(this._onCreate, this);

the _onCreate() method is defined as :

_onCreate: function(oEvent) {
			var oContext = this.getView().getModel().createEntry("/CustomerSet", {
				success: this._fnEntityCreated.bind(this),
				error: this._fnEntityCreationFailed.bind(this)
			});
			this.getView().setBindingContext(oContext);
		},

I get this error in my console log :

I also tried instead of calling the attachPatternMatched() method :

this.getOwnerComponent().getModel().metadataLoaded().then(
				this._onCreate()
			);

But it seems no better :(.

Is anyone has an idea please ? Is there any comprehensive documentation on basic generated templates and why are each code lines is called ?

Thank you for your help.

Regards,

Olivier

Accepted Solutions (1)

Accepted Solutions (1)

former_member365727
Active Contributor

From the error it is clear that before metadata is loaded you are trying to create entry. To avoid this error create the entry after checking that metadata is loaded.

_onCreate: function(oEvent) {
     var oModel = this.getView().getModel();
     var that = this;
     oModel.attachMetadataLoaded(function(){
			var oContext = oModel.createEntry("/CustomerSet", {
				success: that._fnEntityCreated.bind(this),
				error: that._fnEntityCreationFailed.bind(this)
			});
			that.getView().setBindingContext(oContext);
     });
},

Answers (1)

Answers (1)

former_member512938
Participant
0 Kudos

Thank you Srikanth !