2
votes

I'm implementing pop up screen on save button as OK and cancle.when i press OK on popup it should hit the oDATA for which I have impelmented the code as shown below.

Detail controller:

    onPress: function(){
        MessageBox.confirm("Would you like to Save the Material Document No?",{
            title: "Confirmation of Material Doc No/Reservation No",
            onClose: this.handleOnClose
        });
    },

    handleOnClose: function(status){
        debugger;

        if(status === "OK"){
                var oEntry = {};
                oEntry.Mblnr = this.getView().byId("idMaterial").getText();
                oEntry.Mjahr = this.getView().byId("idYear").getText();
                oEntry.Rsnum = this.getView().byId("idReservation").getText();
                var oModel = this.getView().getModel();
            oModel.create("/SaveDataSet", oEntry, null, {
            success : function() {

            MessageToast.show("Your data has been saved successfully");
            },error:  function() {
                MessageToast.error("Material Exist In table");
}
        });

But oEntry.Mblnr = this.getView().byId("idMaterial").getText(); is giving error

Uncaught TypeError: this.getView is not a function

2

2 Answers

1
votes

Try this. This will pass the original this to the function.

Hope it helps

   onClose: this.handleOnClose.bind(this)
0
votes

Try below code; ...this keyword is now assigned to a local variable of the function.

  onPress: function() {
    MessageBox.confirm("Would you like to Save the Material Document No?", {
      title: "Confirmation of Material Doc No/Reservation No",
      onClose: this.handleOnClose
    });
  },

  handleOnClose: function(status) {
    debugger;

    var that = this;

    if (status === "OK") {
      var oEntry = {};
      oEntry.Mblnr = that.getView().byId("idMaterial").getText();
      oEntry.Mjahr = that.getView().byId("idYear").getText();
      oEntry.Rsnum = that.getView().byId("idReservation").getText();
      var oModel = that.getView().getModel();
      oModel.create("/SaveDataSet", oEntry, null, {
        success: function() {
          MessageToast.show("Your data has been saved successfully");
        },
        error: function() {
          MessageToast.error("Material Exist In table");
        }
      });
    }
  }