cancel
Showing results for 
Search instead for 
Did you mean: 

sap.m.message box onClose is not working

former_member127164
Participant
0 Kudos

hi i am trying to display a message box and based on action on message box it should undergo the condition.

jQuery.sap.require("sap.m.MessageBox");
     sap.m.MessageBox.show(
      "Please Confirm to Submit", {
         icon: sap.m.MessageBox.Icon.INFORMATION,
         title: "Dear User",
       actions: [sap.m.MessageBox.Action.YES, sap.m.MessageBox.Action.NO],
       onClose: function(oAction){
       if(oAction == "YES"){var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
      oRouter.navTo('default');}

       },
       }
     );

here i am trying to navigate to another view if i select YES button  in message box.but it is not happening.can u help where i went wrong?

Accepted Solutions (1)

Accepted Solutions (1)

former_member182862
Active Contributor

I think it should be

jQuery.sap.require("sap.m.MessageBox");

sap.m.MessageBox.show("Please Confirm to Submit", {
    icon: sap.m.MessageBox.Icon.INFORMATION,
    title: "Dear User",
    actions: [sap.m.MessageBox.Action.YES, sap.m.MessageBox.Action.NO],
    onClose: function(oAction) {
        if (oAction == "YES") {
            var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
            oRouter.navTo('default');
        }
    }.bind(this)
});

Thanks

-D

Former Member

I feel this answer needs a lot more likes...

This is the correct answer.

To expand, the reason the original poster's code didn't want to work, is that he was trying to reference "this" within the Callback function of the MessageBox, which, in the callback instance, refers to the MessageBox, and NOT the View as the OP seemed to have thought.

Once the "View's this" is bound to the MessageBox, the Callback Function can now refer to that object in it's Async "thread", and can access functions/attributes of the View, like this.handleOnSave, or getRouter(this).

Thanks to for this answer, it has saved me hours of trying to work around ASYNC calls within the SAPUI5 framework.

kreshnikp
Discoverer
0 Kudos

Thanks man, appreciate it.

Just saved me a lot of time 🙂

All the best.
Kreshnik

Answers (3)

Answers (3)

former_member127164
Participant
0 Kudos

if possible can anyone post an example in jsbin

agentry_src
Active Contributor
0 Kudos

Please mark this Discussion with a Correct Answer (closes, but does not lock the Discussion) and Helpful Answer where appropriate. See http://scn.sap.com/community/support/blog/2013/04/03/how-to-close-a-discussion-and-why   Even if you discovered the solution without any outside contributions, it helps others to understand what the solution turned out to be. 

Do not use Assumed Answered as it confuses anyone looking for the specific answer.  If you dig into the Getting Started link (top right of each SCN page), you are only instructed to mark Helpful or Correct Answers to Discussion responses. 

Thanks, Mike (Moderator)

SAP Technology RIG

NagaPrakashT
Contributor
0 Kudos

Hi Sunnel,


I don't see problem with your code. I have tested and i am able to close the message box.

Where exactly you are facing the issue.


Thanks,

Naga

santhu_gowdaz
Active Contributor
0 Kudos

try,

  if (oAction === sap.m.MessageBox.Action.YES) {

former_member127164
Participant
0 Kudos

this is also not working.After pressing yes button in sap.m.message box the if condition has to be executed but it is not working.

santhu_gowdaz
Active Contributor
0 Kudos

See this example-

Edit fiddle - JSFiddle