on 04-22-2016 9:32 AM
Hello Experts
I am trying to get get message returned from backend system on successful update / create request, but the code returns nothings and when I check in debug mode it bypasses the success / error functions in oDataModel's create/update methods.
Below is my code:
var oServiceModel = this.getView().getModel();
var relPath = "/IssueDetailSet(" + "Memberid=" + "'" + memberid + "'" + "," + "Bookid=" + "'" + bookid + "'" + ")";
// Call the update method of the service model
oServiceModel.update(relPath, oData, null, function(success) {
MessageToast.show("Updated book " + success.Bookid);
},
function(error) {
MessageToast.show(JSON.parse(error.response.body).error.message.value);
});
at Backend Side I am passing data in UpdateEntityset to below Method
COPY_DATA_TO_REF(
exporting
IS_DATA = LS_REQUEST_INPUT_DATA
changing
CR_DATA = ER_ENTITY
).
Date is going fine and update working fine but I am not sure how to get return Sucess message in JS above
yes Mayank
you are Right there was problem in the syntax itself , I have already used the above syntax and now it works fine !!
But there is a small problem now that response does not return anything on success
but if I raise some exception as below , response returns an error values accordingly.
RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception
* EXPORTING
* message_container = LO_MESSAGE_CONTAINER.
How can I add some value in response in case of success.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
error: function (oError) {
MessageBox.show(
JSON.parse(oError.response.body)["error"]["message"]["value"], {
title: "Error"
}
); --> outer
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Mayank !
Problem solved
Thanks Ankit for all the Help!! Appreciated
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Can you try like this and check if anything goes into console. Also what is status and response of the request in chrome debugger - network tab.
oModel.update(path, oData, {
success: function(oData, response)
{ console.log(oData, response); },
error: function(oData, response)
{ console.log(oData, response); }
});
Regards,
I applied the Break point
But even on applying break point thru console it does not return at success / error function even after hitting back end and update happens without any response back
I applied BP at line 69 and line 75 but it did not return there even after sometime and processing was fully complete
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Help required Experts !
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello KC,
Multiple ways are there to pass message from backend to UI.
1. Either add two properties message type and message in the structure for 'er_entity' and populate them. Then you can pass 'er_entity' as you are doing now and it will have the messages. This is not a good way though.
2. A better way is to instantiate a message container and add the messages there which will be available as header in the response of Odata call.
Sample -
Data : lo_message_container TYPE REF TO /iwbep/if_message_container.
*-- At least one message is there - Instantiate a Message Container and use the same
CALL METHOD me->mo_context->get_message_container
RECEIVING
ro_message_container = lo_message_container.
*-- Pass messages returned from UI Request Handler API to oData Message Container
CALL METHOD lo_message_container->add_messages_from_bapi
EXPORTING
it_bapi_messages = lt_bapi_message " Source of message
iv_add_to_response_header = abap_true.
BR.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Ankit
Still the success function is getting bypassed as you can see below in highlighted text.
Also the value at back-end is getting passed to METHOD lo_message_container->add_messages_from_bapi
Highlighted text LS_REQUEST_INPUT_DATA-BOOKID has value but nothing is getting returned back in Success.Bookid in function above in JS.
Hi KC,
The call to success and error handler functions are done asynchronously (makes sense also) because backend processing takes some time. So put a debugger statement in both and check.
Backend code seems correct. To be able to get the message as part of HTTP header modify the success/error handler and include a second argument. Example-
function(oData,oResponse) {
var sCompleteMessage = oResponse.headers["sap-message"];
var oMessage = JSON.parse(sCompleteMessage);
MessageToast.show(oMessage.message);
}
BR.
Yes Ankit
got that point so I was expecting it will call the messageToast message after sometime but unfortunately not.
Anyways can you please provide exact implementation of function you are trying to say, I am completely new to JS
below is the code
- oServiceModel.update(relPath, oData, null, function(success) {
- MessageToast.show("Updated book " + success.Bookid);
- },
- function(error) {
- MessageToast.show(JSON.parse(error.response.body).error.message.value);
- });
Hi KC,
Please modify as below and put debugger to check.
oServiceModel.update(relPath, oData, null, function(oData,oResponse) {
var sCompleteMessage = oResponse.headers["sap-message"];
var oMessage = JSON.parse(sCompleteMessage);
MessageToast.show(oMessage.message);
},
function(oResponse) {
var sCompleteMessage = oResponse.headers["sap-message"];
var oMessage = JSON.parse(sCompleteMessage);
MessageToast.show(oMessage.message);
});
BR.
Please put breakpoints as shown and check by pressing F12. Also check the backend system (gateway system if any service error is getting logged)
oServiceModel.update(relPath, oData, null, function(oData,oResponse) {
debugger;
var sCompleteMessage = oResponse.headers["sap-message"];
var oMessage = JSON.parse(sCompleteMessage);
MessageToast.show(oMessage.message);
},
function(oResponse) {
debugger;
var sCompleteMessage = oResponse.headers["sap-message"];
var oMessage = JSON.parse(sCompleteMessage);
MessageToast.show(oMessage.message);
});
Yes applied BP at same places but as you can see it does not go to the response function even after hitting Back-end, at first run code goes to line 79 after update call and does not return to response section afterwards.
There is no error coming from backend accept the message I am passing from there as above
User | Count |
---|---|
82 | |
10 | |
10 | |
9 | |
6 | |
6 | |
5 | |
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.