Skip to Content

Transfer Values Between two SAP UI5 Views

Hello:

I used the example at the following link to try to set, and then read, a model in the Core.

The code in the First (sending) Controller is:

onAddPressed: function(oEvent) {
	var oCustomerID = this.getView().byId("CustomerID").getText();
	var modelParameters = {};
	modelParameters.CustomerID = oCustomerID;
	this.customer.setData(modelParameters);
			
	sap.ui.getCore().setModel(this.customer);			
	var oBindingContext = oEvent.getSource().getBindingContext();
	var oCustomerModel = sap.ui.getCore().getModel('/CustomerID');
	},
onInit: function() {
	this.customer = new sap.ui.model.json.JSONModel();
	this.mBindingOptions = {};
	this.oRouter = sap.ui.core.UIComponent.getRouterFor(this);
	this.oRouter.getTarget("Customer").attachDisplay(jQuery.proxy(this.handleRouteMatched, this));
}

And in the Second (receiving) Controller is:

onAddPressed: function(oEvent) {
	var oCustomerNumber = sap.ui.getCore().getModel("/CustomerID");
}

When I stop on the first line in the receiving Controller, oCustomerNumber is undefined.

Am I forgetting to do something?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    Nov 23, 2017 at 07:36 AM

    Hi,

    In First controller set value like this.

    ap.ui.getCore().setModel(this.customer, "MdlName");

    At receiving controller like this.

    sap.ui.getCore().getModel("MdlName");

    Try this

    Add comment
    10|10000 characters needed characters exceeded

  • Nov 23, 2017 at 11:35 AM

    Hi Ian ,

    Write below code in second controller . This would return all the data that you want in this controller

    var oCustomerNumber = sap.ui.getCore().getModel( );
     var aData = oCustomerNumber.getData();
    
    Add comment
    10|10000 characters needed characters exceeded

  • Nov 23, 2017 at 12:27 PM

    You shouldn't really set data in the core. Why don't you use routing?

    Have a look here at this sample

    Add comment
    10|10000 characters needed characters exceeded

    • It isn't my preference, but seem to be an expedient way to accomplish what I needed (passing a value from one view to another). If I read the code in the sample correctly, you can pass parameters when routing, is that true? (I am new to SAP UI5). I will try to find some additional tutorials, but that seems like a good approach, too!

  • Nov 23, 2017 at 05:00 AM

    Hello Ian,

    Are you sure this line works? Have you checked the returning value?

    var oCustomerID = this.getView().byId("CustomerID").getText();
    

    I assume that the element assigned by CustomerID is sap.ui.commons.TextField. Hence, you should change your code to

    var oCustomerID = this.getView().byId("CustomerID").getValue();

    Regards,

    Tri

    Add comment
    10|10000 characters needed characters exceeded