cancel
Showing results for 
Search instead for 
Did you mean: 

how to define a variable on a controller that has not yet been loaded on a view.

Former Member
0 Kudos

hello experts,

I am facing an issue, when I am trying to use a particular variable on a detail page(variabe is Salesorder), the error is that salesorder is not defined.

But, I have defined the variable in the master page's controller itself.

Now, when I click a particular button,  it doesn't loads the master and details page, but it gives an error that sales order is not defined, since master page's controller is called first.

Here are the screen shots:

detail page

Master .controller

Outputscreen

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

hi sanjo..

why don't you define odata service in your master controller...itself!!

oDataModel.read("/SalesOrderHeaderDetailsInfoSet?$filter= ImSalesorder eq '"+salesOrder+"'and ImUsername eq '"+data.userName+"' ",null,null,false,onSuccessLogin,function(oError){

   console.log("error",oError);});

// 

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

   json.setData({data1:loginResult.results});

   sap.ui.getCore().byId("infoList1").setModel(json);

Hope it's works!!!

Answers (4)

Answers (4)

Former Member
0 Kudos

HI maksim, I am very new to this, could you please explain in detail how to pass the parameter?

former_member182372
Active Contributor
0 Kudos

same code as you have, just pass salesOrder as

var __SalesOrder = y.SalesOrder;

...toDetail("...","....", { SalesOrder : __SalesOrder });





so in you second page you can read it




page1.addEventDelegate({

  onBeforeShow: function(evt) {

//evt.getProperty("data").SalesOrder      

   

    },

});

page1 is where you navigate, you can get it from app

Former Member
0 Kudos

page1.addEventDelegate({

  onBeforeShow: function(evt) {

//evt.getProperty("data").SalesOrder      

   

    },

});

this should be defined in the detail page right??

former_member182372
Active Contributor
0 Kudos

yes

Former Member
0 Kudos

Its showing error, that Page1( in my case detailpage2) is not defined?

former_member182372
Active Contributor
0 Kudos

how do you get it? like app.getPage("accountOrderDetail")?

Former Member
0 Kudos

I defined the odata in the master's controller, now its working..Thanks Maksim for helping me out!!

former_member182372
Active Contributor
0 Kudos

why dont you just pass SalesOrder as 3rd param to  toDetail

toDetail("","", { SalesOrder : SalesOrder });

* @param {object} oData
*         This optional object can carry any payload data which should be made available to the target page. The "beforeShow" event on the target page will contain this data object as "data" property.
*
*         Use case: in scenarios where the entity triggering the navigation can or should not directly initialize the target page, it can fill this object and the target page itself (or a listener on it) can take over the initialization, using the given data.
*
Former Member
0 Kudos

Hi,

define global variable r passing as parameter is wrong method of development. one of soln. is using angular try that

former_member183518
Active Participant
0 Kudos

Are you suggesting a completely different farmework (angularjs) as a solution just for sharing a variable instance across two controllers !!! Seriously ??

Former Member
0 Kudos

hi,

In a high level business use case, sending variable as parameter is not recommended. Angularjs may be diff framework but can be perfect for this use case!

former_member183518
Active Participant
0 Kudos

In the first place this is a *very* simple question!! There are many simpler ways in ui5 we could achieve it. I don't find any reason why variables shouldn't be passed as parameters. Do we define functions without arguments !!

I guess you might have worked out in AngularJs or maybe even a fan of it, but please do consider solutions that UI5 can offer in your answers as its a UI5 community.

former_member182372
Active Contributor
0 Kudos

using Abrams tank for grocery shopping is pretty cool but a little bit overkill 😉

Former Member
0 Kudos

So, what do you suggest?how to pass variables as parameters?

Former Member
0 Kudos

Thanks Maksim, So the variable can be passed as a parameter right?

former_member182372
Active Contributor
0 Kudos

yes, 3rd parameter of toDetail method

toDetail = function(pageId, transitionName, data, oTransitionParameters)

SAPUI5 SDK - Demo Kit

Former Member
0 Kudos

Hi Sanjo,

According to your query, what i am getting is that you want to use the variable defined in the Master page onto the detail page.

So, If my understanding is correct, you need to pass this variable from master view to detail view while navigating.

I would not suggest and even not recommended to define the variable globally until n unless you did not find any other way to crack it.

Hope this helps!!!

Former Member
0 Kudos

Actually, when I am clicking on orders tab in Account, it isn't loading the split view, but it thorws an error that sales order is not defined.

Former Member
0 Kudos

hi,

use require to load the controller in order!

Former Member
0 Kudos

how is it possible to load the detail page after the master controller??

Former Member
Former Member
0 Kudos

so, what this suggest is that variable should be declared globally. I suppose in javscript, we use 'window' to declare a variable globally.

But, when I tried using window, it shows the same error.

Do you suggest any other method?

Former Member
0 Kudos

Hi,

Its not declared globally, i suggest to use angular js concept, which i sent in link above