Search code examples
sapui5messagebox

sap.m.MessageBox.confirm working sap.m.MessageBox.error or sap.m.MessageBox.warning not working


In my sapui5 project i am using sap.m.MessageBox.confirm its working fine but when i use sap.m.MessageBox.error or sap.m.MessageBox.warning it shows error

Uncaught TypeError: undefined is not a function

I have added jQuery.sap.require("sap.m.MessageBox"); still the issue is not solved. please give solution for this problem

Thanks

Sorry for not posting the code earlier

Edited 1

View

 <core:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m"
        controllerName="trial.S1" xmlns:html="http://www.w3.org/1999/xhtml">
    <Page title="Title">
        <content>

        </content>
        <footer>
            <OverflowToolbar>
                <ToolbarSpacer />
                <Button id="errorId" text="Error" type="Accept"
                    press="fnOnerror" />    
                    <Button id="confirmId" text="Confirm" type="Accept"
                    press="fnOnconfirm" />  
            </OverflowToolbar>
        </footer>
    </Page>
</core:View>

Conroller

jQuery.sap.require("sap.m.MessageBox");
sap.ui.controller("trial.S1", {
    fnOnerror : function(oEvent){

         sap.m.MessageBox.error("My error message");

    },
    fnOnconfirm : function(oEvent){
        sap.m.MessageBox.confirm("My Confirm message")
    }

});

index.html

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta http-equiv='Content-Type' content='text/html;charset=UTF-8'/>

        <script src="resources/sap-ui-core.js"
                id="sap-ui-bootstrap"
                data-sap-ui-libs="sap.m"
                data-sap-ui-theme="sap_bluecrystal">
        </script>
        <!-- only load the mobile lib "sap.m" and the "sap_bluecrystal" theme -->

        <script>
                sap.ui.localResources("trial");
                var app = new sap.m.App({initialPage:"idS11"});
                var page = sap.ui.view({id:"idS11", viewName:"trial.S1", type:sap.ui.core.mvc.ViewType.XML});
                app.addPage(page);
                app.placeAt("content");
        </script>

    </head>
    <body class="sapUiBody" role="application">
        <div id="content"></div>
    </body>
</html>

Solution

  • How should we give you a solution for your issue if your information is not enough? From what you describe it is hard to tell what you are doing wrong. Make sure to always add more information including code.

    After getting the information from you we know now that you are using version 1.28.9 of UI5. If you would have checked the API docs at https://openui5.hana.ondemand.com/#docs/api/symbols/sap.m.MessageBox.html#.error then you would have known that the APIs you are using were introduced in 1.30!!!