Skip to Content

Handling messages from the server

Hi guys,

I'm waking my first steps in SAPUI5. I trying to develop a basic app that allows to change some data from customers ( KNA1). I had developmented the oData service in the backend (SEGW ), added the service in gateway( /IWFND/MAINT_SERVICE ) and finally configured the Cloud Connector....etc

So I created a proyect (masterDetail template) and everything was working fine until I tried to handling messages from the server. After I read a lot of blogs and posts it seems that then only thing that I need to do is add this lines in the onInit function.

		onInit: function() {


var oMessageProcessor = new sap.ui.core.message.ControlMessageProcessor();
var oMessageManager = sap.ui.getCore().getMessageManager();
this.oMessageProcessor = oMessageProcessor;oMessageManager.registerMessageProcessor(oMessageProcessor);

With the above code I was expecting that message manager automatically handle the messages that are comming from the server and then, a message indicator shows up in the screen telling me that are pending messages to see.

Here is the mesage indicator element that I have inserted in the Detail.view.xml

<semantic:messagesIndicator>
<semantic:MessagesIndicator tooltip="Mensajes" id="__indicator0" press="onMessagesButtonPress"/>
</semantic:messagesIndicator>

Here is the udpate operation that I'm triggering when I click the save button in the screen

		this.getView().getModel().update(sPath, {
			Kunnr: sKunnr,
			Stras: sStrass
		},
		{
				groupId: "A1"
		}
		);
// Disparo los cambios realizados
this.getView().getModel().submitChanges({
				groupId: "A1",
       success: function (Odata, response){
                 this.getView().getModel().refresh(true);
				}.bind(this),
	error: function(){
                 sap.m.MessageToast.show("error function");					
//                 this.getView().getModel().refresh(true);
				}.bind(this)
			});

I'm grouping all the operations under A1 batch group ID.

	handleEditPress: function() {
	    this.getView().getModel().setDeferredGroups(["A1"]);

These are the screens of the App ( before press Edit button )

After press edit button

The update it's working fine in the backend, but the message manager is not handling the messages that are comming from the backend.

Here is the parameter oData from the "success" function (inside the submitChanges).

As you can see above messages are comming("Cliente actualizado".....), but if I take a look in the message manager messages are not being parsed as you can see below

The above code from the console was typed when the debug stop on the the success function.

I don't want to make this post more extensive because it can be too much info at once. So please let me know if you need more info from my side. As I mentioned before these are my first steps in SAPUI5, I have been an abaper for 5 years but I'm new in this, so excuse me is I'm making dummy questions here je.

Thanks in Advance for all the help that you can give me.

edit.jpg (32.6 kB)
after-edit.jpg (45.4 kB)
odata-response.jpg (33.5 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Jul 20, 2017 at 07:23 AM

    I observe that you have defined two variables: oMessageManager and oMessageProcessor.

    The error gets generated in the oData service call but I do not see that error is mapped to the message manager variables. Hence, when you check in console, the message manager is undefined or empty.

    As a simple practice, you can always get the error text (inside the error function) and save it into a local JSON model( similar to local variable but as a json model - sap.ui.model.JSONModel). This model can be mapped to a control int he view.

    Regards,

    Sharath

    Add comment
    10|10000 characters needed characters exceeded

  • Jul 21, 2017 at 01:23 AM

    First of all thanks for your reply Sharath.

    In this case there are not error messages, as I mentioned before the udpate on the backend was successfull so success function was triggered, and in that moment I declared the variables in the console to see if the messages were properly parsed, unfotunately it wasn't the case. My doubt here is, message shouldn't be automitacally parsed and handle it by the message manager???.

    
    SPAN {
    font-family: "Courier New";
    font-size: 10pt;
    color: #000000;
    background: #FFFFFF;
    }
    .L0S52 {
    color: #0000FF;
    }
    .L0S55 {
    color: #800080;
    }
    
        DATA lo_message_container TYPE REF TO /iwbep/if_message_container.
    
    SPAN {
    font-family: "Courier New";
    font-size: 10pt;
    color: #000000;
    background: #FFFFFF;
    }
    .L0S31 {
    font-style: italic;
    color: #808080;
    }
    .L0S33 {
    color: #4DA619;
    }
    .L0S52 {
    color: #0000FF;
    }
    .L0S55 {
    color: #800080;
    }
    .L0S70 {
    color: #808080;
    }
    
          CALL METHOD lo_message_container->add_message
    
            EXPORTING
    
              iv_msg_type               = 'S'
    
              iv_msg_id                 = 'SABAPDOCU'
    
              iv_msg_number             = '888'
    
              iv_msg_text               = 'Cliente actualizado exitosamente'
    
              iv_msg_v1                 = 'Cliente actualizado exitosamente'
    
    *         iv_msg_v2                 =
    
    *         iv_msg_v3                 =
    
    *         iv_msg_v4                 =
    
    *         iv_error_category         = /IWBEP/IF_MESSAGE_CONTAINER=>GCS_ERROR_CATEGORY-PROCESSING
    
            iv_is_leading_message     = ABAP_TRUE
    
    *         iv_entity_type            =
    
    *         it_key_tab                =
    
    *Es importante cambiar el valor por default a true en los mensajes de exito para  que el mismo
    
    * viaje a front end
    
              iv_add_to_response_header = abap_true
    
    *         iv_message_target         =
    
     .
    
    

    Above is the from the backend ( abap code ) that I'm using the send the messages to frontend .

    Please le me know if something is not clear or if you need more info from my side. Below is an image of that I'm excpeting to see in the screen

    Regards,

    Adrian Coria.

    Add comment
    10|10000 characters needed characters exceeded