on 11-28-2019 7:40 AM
Hello,
I have implemented OData batch processing and have the following problem.
Even though a business exception is raised in the back end, error call back never gets triggered.
(I found it triggerred only when there's a connection error)
My back-end code for raising exception
if sy-subrc <> 0.
io_message_container->add_message_from_bapi(
exporting
it_bapi_messages = lt_return
iv_add_to_response_header = abap_true
)
raise exception type /iwbep/cx_mgw_busi_excetion
exporting
message_container = io_message_container.
endif.
Front-end code for calling submitChanges
oModel.submitChanges({
success: function(oRes) {
//some code;
},
error : function (oErr){
//some code;
},
groupId: sBatchGroup
});
When a exception is raised, I can see error message in console, but error call back is not triggered.
I've read below threads regarding this issue, but haven't got the solution yet.
https://answers.sap.com/questions/12184545/submitchanges-error-callback-not-working-in-versio.html
https://answers.sap.com/questions/12269639/odata-submitchanges-error-handling.html#
What I need to do is to show a message popover with messages returned from server.
It seems that messages are not coming to message popover unless OData request failes...
Regards,
Mio
The Issue has been resolved by passisng "iv_message_target" to "add_message" method.
( "add_messages_from_bapi" didn't have this parameter).
After that MessageManager started to recieve error messages from back-end.
<back-end code>
lv_target = |/Header('{<objectKey>}')|.
io_message_container->add_message(
Exporting
iv_msg_type = 'E'
iv_msg_id = 'ZMSGCLASS'
iv_msg_number = '000'
iv_is_leading_message = abap_ture
iv_add_to_response_header = abap_ture
iv_message_target = lv_target
) .
raise exception type /iwbep/cx_mgw_busi_excetion
exporting
message_container = io_message_container.
<front-end code>
As submitChanges callback falls success even there's error from backend, I needed addithonal check for error.
oModel.submitChanges({
success: function(oRes) {
//Additional check for backend error
if( !that._responseHasError(oRes) ){
//Execute Success function
}
},
error : function (oErr){
//Execute Error function
},
groupId: sBatchGroup
});
_responseHasError: function(oRes) {
var bStatusExists = "response" in oRes.__batchResponses[0];
if (!bStatusExists){
return false;
}
else if ( oRes.__batchResponses[0].response.statusCode >= 400 ){
return true;
}
return false;
},
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes. This app was first implemented with create method and error handling was working as expected.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mio
In my case none of the handlers (no success, no error) are called... what is wrong??
//Daten ans Backend senden
//oOdataModel.setDeferredGroups(["CreateInvDoc"]);
for (i = 0; i < aJsonModelData.length; i++) {
oOdataModel.create("/CountSet", {
"Mat": aJsonModelData[i].Mat,
"Plant": aJsonModelData[i].Plant,
"StorLoc": aJsonModelData[i].StorLoc,
"Bat": aJsonModelData[i].Bat,
"CountQty": aJsonModelData[i].CountedQty,
"Unit": aJsonModelData[i].Unit
});
}
oOdataModel.submitChanges({
// groupId: "CreateInvDoc",
success: this.onUpdateSuccess,
error: this.onUpdateError });
onUpdateError: function (oError){
MessageToast.show("Fehler");
console.log(oError.toString());
},
The Inserts go to the backend as batch... everything is nice... but I need the handlers... imho they should also be called without message manager. any ideas?
Regards
Daniel
Hi Daniel,
You can check if batch call was success with below code.
If the call was success, ODataModel should not have pending changes anymore.
Error callback of submitChanges is only called when call to the backend itself failed (such as connection error).
oOdataModel.submitChanges({
success: function () {
if (oOdataModel.hasPendingChanges()) {
//error callback
}
else {
//success callback
}
},
error : //called on connection error
});
Regards,
Mio
Hi Mahesh,
Messages are supposed to be displayed automatically, once you add below code to controller's init method, and add MessagePopover control to the view.
MessaegManager takes care of fetching and displaying messages.
var oMsgManager = sap.ui.getCore().getMessageManager();
this.getView().setModel(oMsgManager.getMessageModel(), "message");
oMsgManager.registerObject(this.getView(), true);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
89 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.