Skip to Content

CRUD operations in SAPUI5

Aug 29, 2017 at 09:33 AM


avatar image

Hello Guys,

I am learning CRUD operations in SAPUI5.I have come across the createEntry() method of the ODATA model,and I am unable to use it.I am looking for an working example to demonstrate the use of the createEntry() method.

Thanks in Advance.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
avatar image
Former Member Aug 30, 2017 at 09:19 AM

Hi Arjun Biswas,

createEntry() simply creates a new record for the given path in the OData model with a temporary key and returns the context for that newly created object. It will not automatically create the entity in the backend until you call a submit().

I think a normal use case for this if you want to create an entity without submitting it to the back-end until a user has entered some additional data. Just imagine a "Product Maintenance" App where the user clicks on a "New Product" button. You would call something like this in the Button Event Handler:

		var oContext = this.getModel().createEntry("/ProductSet", {
				properties: oData, //Some optional data you want to set initially 

Then you would navigate to a product creation view and bind the Context you got from createEntry to that creation view. After the user has entered all necessary data on that creation page he would press a save or cancel button. In these event handlers you would call something like:

                onSave: function(oEvent) {
				success: function(oData) {
				error: function(oData) {
					//Error message

		onCancel: function(oEvent) {

I contrast to that you can call methode create() instead of createEntry(). It will automatically do a back-end call with the new data record (if it is not in a deferred group)

Hope that helps.


Show 3 Share
10 |10000 characters needed characters left characters exceeded

Thank you Tobias Schnur ,

This is my code :-

var oModel = this.getModel(); 
	_onMetadataLoaded: function() {
			// create default properties
			var oProperties = {
				ProductID: "" + parseInt(Math.random() * 1000000000, 10),
				TypeCode: "PR",
				TaxTarifCode: 1,
				CurrencyCode: "EUR",
				MeasureUnit: "EA"
			// create new entry in the model
			this._oContext = this.getModel().createEntry("/ProductSet", {
				properties: oProperties,
				success: function(){alert("Successfully created");}
			// bind the view to the new entry

On adding a new record from my UI,I donot get any success message.Could you tell me where I am going wrong.

Former Member
Arjun Biswas

Hi Arjun Biswas,

I never used a success callback with createEntry method but I guess it's not called as long as you do not submit your changes to the backend. As mentioned in my last post "createEntry" does not send anything to the back end. It only creates an entry in the Request Queue. See:

If you submit your changes successfully to the back end (i.e. not getting any http error code) your sucess handler should be called.

Alternatively you can call "this.getModel().create(....) instead of "this.getModel().createEntry(...)". This will automatically submit your changes.

The Idea behind this is simply. "createEntry" allows a deffered submit. Sometimes you want to create an entity (in the front-end) but you need more user interaction (e.g. filling some manadatory fields) before you can actually send it to the backend. If this is not the case you should stick with "create" methode instead.




Thank you so much.

Sharath M G Aug 29, 2017 at 10:40 AM

CRUD operations are for the oData service. Nothing to do with UI5. In UI5, you will simply call the entity and in the oData the CRUD operatons are executed.

Check with oData design and development for more on CRUD operations.

Show 1 Share
10 |10000 characters needed characters left characters exceeded

I went through this document and cannot use the functionality of create entry function.

Jun Wu Sep 01, 2017 at 11:54 AM

you can skip createentry for now, it is a bit advanced topic.

10 |10000 characters needed characters left characters exceeded