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 comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

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 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 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 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 comment
    10|10000 characters needed characters exceeded

    • 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