Skip to Content

sap.m.message box onClose is not working

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?

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    Posted on Aug 13, 2015 at 05:50 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

    • 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 @Dennis Seah for this answer, it has saved me hours of trying to work around ASYNC calls within the SAPUI5 framework.

  • Posted on Aug 10, 2015 at 09:43 AM

    try,

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

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 10, 2015 at 09:55 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 10, 2015 at 04:54 PM

    if possible can anyone post an example in jsbin

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.