cancel
Showing results for 
Search instead for 
Did you mean: 

ODATA V4 RAP - How to retrieve messages in response

Victor_Alvarez
Participant
0 Kudos
645
Spoiler
 

Dear Support.

We want to call an api created on RAP ( Odata V4).  We read information about our question here https://sapui5.hana.ondemand.com/sdk/#/topic/fbe1cb5613cf4a40a841750bf813238e.html and here https://help.sap.com/docs/ABAP_PLATFORM_NEW/fc4c71aa50014fd1b43721701471913d/b9a77576783a455cbff617c...

Upon appending messages in failed messages, they are correctly displayed in the response payload. However, when we append information or success messages in the reported section, for example:

 

Victor_Alvarez_0-1712299133719.png

 

Messages are included in the response header, with a limitation of 20 records.

 

Victor_Alvarez_1-1712298929431.png

 

But not in response payload

Victor_Alvarez_2-1712298959204.png

Is there any chance to report messages in the response payload? How are then appended the messages?

Regards

 


 

 

 

 

 

View Entire Topic
TK4
Discoverer
0 Kudos

Hi,

I'm also trying to figure this out. If you're developing using freestyle SAPUI5 and Javascript, you could get those messages like this:

SCENARIO 1: I want to get all messages from my currently running session

 

 

// prerequisites: any combination that triggers POST call to backend, example below - I assume you have it
let oBinding = oModel.bindList("/EntityPath"); // access create method via list binding
oBinding.create({...}); // one or multiple .create() calls
oModel.submitBatch("batchCreate"); // summarized in one batch

// you need just this snippet to get all messages from your current session: if you don't mind, that you can't delete previously received ones
oModel.attachDataReceived(function (oEvent) {
        let oSource = oEvent.getSource();
        let aMessages = oSource.getModel().getMessagesByPath("/EntityPath");
    });

 

 

SCENARIO 2: I only want to get new messages every time I'm creating an entity, so I don't get old irrelevant information

 

 

oModel.attachMessageChange( function(oEvent) {
      let aMessages = oEvent.getParameter("newMessages");
      oEvent.getSource().setMessages({ "/EntityPath": aMessages });
} );

 

 

Instead of calling .attachDataReceived(), you could also utilize MessageProcessor by .attachMessageChange() ( hiding in oEvent.getSource() ) and set your messages either by receiving only new messages (in parameter newMessages) or even including oldMessages parameter (refer https://sapui5.hana.ondemand.com/sdk/#/api/sap.ui.core.message.MessageProcessor), if exists.

I would recommend some independent storage for that data (ex. custom data). Overriding existing Message arrays/objects might get tricky, because you're still at risk of mixing old messages with new ones.

EntityPath is obviously your alias connection to entity maintained in Service Definition - I assume you have it covered as well.

Although, I'm not sure whether you can receive details about your Entity Key in particular message. I think this has to be maintained manually. If someone knows how to achieve it directly, let us know.

TK4
Discoverer
0 Kudos
I've edited the post to cover both possible scenarios. Feel free to adjust it to your needs, probably scenario 2 is the one you're looking for.