jao6693
jao6693

Reputation: 101

SAPUI5: sap-message not retrieved using getHeaders()

I use the functionality of mapping messages from a SAP Gateway Service to the header of the response of an OData request. This allows me to receive on the client side the messages from a backend directly in an http-header called SAP-message

Unfortunately, and although I can see the SAP-message header in the response headers of my Odata response in the Chrome Dev Tools, when using the getHeaders method of the OData Model class, this particular header is not returned

Here is the code I use:

oModel.create("/PurchaseContractHeaderCollection", mPayload, {
    async : true,
    success : jQuery.proxy(function(mResponse) {
        // get headers
        var mHeaders = this.oModel.getHeaders();
        // SAP-message is not mapped in the headers of the OData model

As a result, mHeaders doesn't contain any SAP-message object

Here is the content of the response headers visible in the Chrome Dev Tools:

content-length:705
content-type:application/json; charset=iso-8859-1
dataserviceversion:2.0
location:http://<server>.<domain>/PurchaseContractHeaderCollection('xxxxxx')
sap-message:{
    "code":"ME/887",
    "message":"Erreur lors de la reprise des données ExtensionIn pour l'extension",
    "severity":"warning","target":"",
    "details":[
        {"code":"BAPI/000","message":"Exception","target":"","severity":"info"},
        {"code":"06/017","message":" créé(e)","target":"","severity":"info"}
    ]}
server:SAP NetWeaver Application Server / ABAP 731

Any idea on where the issue lies?

Upvotes: 0

Views: 3630

Answers (1)

jao6693
jao6693

Reputation: 101

I got that answer from SAP:

The ODataModel.getHeaders function is only there to access the request headers which were set by the application beforehand and the ODataModel itself - You cannot access the response header via this function

Use the following code instead:

oDataModel.create(...
    {success: function (oData, oResponse) {
        // access response headers here: oResponse.headers
        ...
}});

Upvotes: 3

Related Questions