cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with Routing when called inside JSON response

Former Member
0 Kudos

Hi,

I am trying to display a view upon the login authentication post the button click .

Login.controller.js

sap.ui.define([

   "sap/ui/core/mvc/Controller",

   "sap/m/MessageToast",

   "sap/ui/model/json/JSONModel"

], function (Controller, MessageToast, JSONModel) {

   "use strict";

return Controller.extend("n_cloudonvoice.controller.Login", {

actLogin: function () {

    var oRouter = sap.ui.core.UIComponent.getRouterFor(this); ///////////////// Router navigation Work well Here which I dont want /////////////

  oRouter.navTo("Campaign");

     var sURL = "/destinations/cloudonvoice?method=checkLoginForSap&user=" + this.byId("inpLogin").getValue() +

                    "&pass=" + this.byId("inpPWD").getValue(); // compile URL to call

       var oModel = new sap.ui.model.json.JSONModel();

    

    oModel.loadData(sURL,"",true);

oModel.attachRequestCompleted(function() {

      var name = oModel.getProperty("/User/0/name"); 

MessageToast.show("Welcome "+name +" !!! ");

var oStorage = jQuery.sap.storage(jQuery.sap.storage.Type.local);

oStorage.put("cloudonvoice_authdata", oModel);

var oRouter = sap.ui.core.UIComponent.getRouterFor(this); ///////////////// Router navigation doesnt Work  Here which I  want /////////////

oRouter.navTo("Campaign");

});

}

   });

});

If someone can guide me where I am going wrong .

Plz suggest.

Rg

Accepted Solutions (1)

Accepted Solutions (1)

junwu
Active Contributor
0 Kudos

check if this helps

var that=this;

oModel.attachRequestCompleted(function() {

      var name = oModel.getProperty("/User/0/name");

MessageToast.show("Welcome "+name +" !!! ");

var oStorage = jQuery.sap.storage(jQuery.sap.storage.Type.local);

oStorage.put("cloudonvoice_authdata", oModel);

var oRouter = sap.ui.core.UIComponent.getRouterFor(that); ///////////////// Router navigation doesnt Work  Here which I  want /////////////

oRouter.navTo("Campaign");

});

}

   });

});

Former Member
0 Kudos

Thanks Mr Wu.

You made my day .

Answers (0)