cancel
Showing results for 
Search instead for 
Did you mean: 

how to use the submitChanges method ?

0 Kudos

hello experts

in my project i am using the submitChanges method like below

	this.oModel.submitChanges({
		groupId: "addRequ",
		error: this.fnError.bind(this),
		success: this.fnSuccess.bind(this)
		
			});

the problem is that it is always generating the success method even when there are errors in the request

how to handle it please ?

Accepted Solutions (0)

Answers (2)

Answers (2)

MioYasutake
Active Contributor

Hi may55,

You can check if submitChanges was successful by oModel.hasPendingChanges() method.

If hasPendingChanges returns true, it indicates that the change was not successful.

You can determine success / error by the following code.

success: function () {
  if (oModel.hasPendingChanges()){
    //error handling
  }else {
    //success  
  }
}

If you have registered the view with MessageManager, it receives error messages returned from the backend.

Regards,

Mio

0 Kudos

hello

actually a am using a messageManager and it is showing me the errors but i dont know how to connect the messageManager with the submitChanges function

thank you

MioYasutake
Active Contributor
0 Kudos

You don't have to connect MessageManager with submitChanges function, but only need to register the view with the MessageManager. Then all messages the view receives are automatically collected by the MessageManager.

If something is not working, could you tell me the details?

0 Kudos

hello

thank you for your help .

this works fine but i have another question.

how is it possible to handle validations in a smart table. actually i have an editable smart table and some required fields . is it possible automaticly with Message Manager?

thank youu

MioYasutake
Active Contributor
0 Kudos

What about setting nullable="false" to the entity's property? (in SEGW)

By doing so the filed will become mandatory.

Please take a look at below sample.

https://sapui5.hana.ondemand.com/#/entity/sap.ui.comp.smartfield.SmartField/sample/sap.ui.comp.sampl...

But I'm not sure if this work with SmartTable.

0 Kudos

hello

this is working with my smart for but it is not working with my Smart table .

have a look at this solution and tell me if you have any ideas : this link

thank you very much

jhodel18
Active Contributor
0 Kudos

Hi Abdallah,

Just an additional answer to Mio Yasutake's response, the .submitChanges() method always return success because that function corresponds to the $batch operation of OData service. The $batch operation always ends up successfully as long as the operation was successfully processed by backend even though some of the actual operations inside the $batch have failed.

To handle the errors, you need to handle the error on the individual operation executed by the methods .createEntry() and .update(), or you could make use of MessageManager to do that for you.