cancel
Showing results for 
Search instead for 
Did you mean: 

DS.loadDataSource() ignores Variable Initialization

Former Member

I am trying to boost performance of my application by switching some of my data sources to Load in Script = true, and then calling the DS.loadDataSource() in my script when an event happens. However, I noticed that although it refreshes the data source, it doesn't use variables set in Variable Initialization.

I have found the following thread with a solution:

https://archive.sap.com/discussions/thread/3718981

and I have moved my APPLICATION.setVariableValue commands from Variable Initialization to the On Click script. So when the user clicks on the component, the script loads the datasource and then applies the variables. OK, it works. But...

I find that it completely negates the purpose of loading data in scipt - every time the user clicks on the component, not only does it load the data source (for which there is no penalty, as I have read in someone's blog, so that's OK), but it resets the variables each time (which kills the performance completely).

Am I right in thinking that the DS.loadDataSource() makes sense only if there are no variables to set on initialisation? Is there a way to test if the data source requires loading and only load it and reset variables when it has not been loaded?

Many thanks,

Agata

Accepted Solutions (1)

Accepted Solutions (1)

kohesco
Active Contributor
0 Kudos

the global variable is the initial state, so you can set as "0".

On component event trigger you set

if 0 {loaddatasource and variableGBP and state = 1}

next time people click on it nothing will happen because state=1 and nothing should happen if I understood well, so everybody happy.

Former Member

So I do the following:

if (state = 0) {

DS.loadDataSource();

DS.setVariableValue("S_FIWIPC", "GBP");

state = 1;}

Is that correct? Thanks!

kohesco
Active Contributor
0 Kudos

state == 0

but yeah that's the idea

Former Member

Yes, I had == and then removed it 🙂

Thanks, I would like to mark your answer as correct, but I don't think I can do it in a comment. If you want, you could copy and paste your seconod comment as an answer and then I can mark it as correct.

kohesco
Active Contributor
0 Kudos

🙂 thanks! happy designing 🙂

kohesco
Active Contributor
0 Kudos

done.......

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi,

the function DS.isInitialized() returns false if the data source is not loaded. It you would help you:

if (DS.isInitialized()==false) {

DS.loadDataSource();

DS.setVariableValue("variable", "value");

}

Regards,

Giulia

Former Member

I don't think I can mark two answers as correct. But yours is definitely easier, as it doesn't require defining global variables.

former_member265529
Contributor
0 Kudos

Hi Lukas,

Yes It happens. Because the data sources will load initially in your application when you use DS.LoadDatasource(); But also your application will again hit your data base when you set value for the variables. This is how it work. So in your case the datasource is loading two times back to back.

You can split the datasources loading places and load only the datasources that are required based on view and set the variable value accordingly. So if you need 2 datasouces in first view of your application load only that and load others in their respective views of the application.

Thanks,

Poovarasan

Former Member
0 Kudos

>>> So if you need 2 datasouces in first view of your application load only that and load others in their respective views of the application.

That's sounds ok, and that's what I am trying to do. But every time I will switch to that view the other data sources will load and set variables again. I don't want to do that, as it's slowing things down. I would rather have my user wait extra 5 seconds at the start of the application and load all data sources, than to have him load variables again and again as he clicks through different views of the application. I just don't think that this thing is well thought through - it only works if there are no variables to be set - which is very rare.

former_member265529
Contributor
0 Kudos

Hi Lukas,

You can use DS.setVariableValue(); instead to Application .setVariablevalue();.

So you only pass values for values to respective datasource it will help performance of your application.

Thanks,

Poovarasan

Former Member
0 Kudos

But that doesn't change the fact that I will keep setting those variables over and over, every time my user clicks on the component.

Former Member

Hi,

the function DS.isInitialized() returns false if the data source is not loaded. It you would help you:

if (DS.isInitialized()==false) {

DS.loadDataSource();

DS.setVariableValue("variable", "value");

}

Regards,

Giulia

Former Member
0 Kudos

Perfect!

If you put it in as an answer I will mark it as correct.

Former Member
0 Kudos

I will try to explain it more clearly.

Normally, my application uses On Variable Initialization:

APPLICATION.setVariableValue("S_FIWIPC", "GBP");

and all my data sources get refreshed correctly with GBP values. But only if data sources are set to Load in Scipt = false i.e. do they get loaded at the initialisation.

Now, I want to load my data sources only if the user clicks on a component, so I change the settings to Load in Script = true and in my component On Click, I add code:

DS_X.loadDataSource(); for all my data soureces I want to load.

But, when the user clicks on the component, the data sources gets loaded but they ignore "S_FIWIPC"="GBP". Instead they load with the initial view (as in the design mode), which is, say, USD data. In order to force it to be GBP I add another line of code to my component On Click script, which looks like this now:

DS.loadDataSource();

APPLICATION.setVariableValue("S_FIWIPC", "GBP");

This is ALL the code that I have in On Click, so there is really no more to paste.

This refreshes the datasource and applies GBP, my user sees GBP data in his dashboard. All fine, problem solved.

But, then the user clicks on the component again. The data source loads (no penalty in performance) AND sets "S_FIWIPC"="GBP" AGAIN, which takes time (this is what I mean by "it resets the variables each time"). It does because it does APPLICATION.setVariableValue("S_FIWIPC", "GBP") every time the user clicks on the component, although there is no need, as he's already done it once.

To summarise: I only want to initialise the variables for my data sources once, not set them every time the user clicks on the component which seems like a forced behaviour if I want to use loadDataSource().

I hope it's a bit clearer now.

A.

kohesco
Active Contributor
0 Kudos

Hi,

I noticed that as your DS is in script = true, no prompts are facilitated in Design Studio. Only when you set as false, you can set the variables. I could use a work a round to set default values in my variables who are applied while loaddatasource.

Works as designed I presume.

The reload by component can be avoided using a state global variable, Boolean type, and in code if state = 0 else if state = 1 ..

Grtz

Koen

Former Member
0 Kudos

Thank you for the hint. I will try that. But how do I reference that global variable to the data source state? What is the JS command for that?

former_member241445
Participant
0 Kudos

Hi Agata.

Maybe screenshots or code can exprees more clearly. As I understanding,if you set Script=true,you need DS.LoadDataSource() before setvariable.

Thanks.

Jing

MustafaBensan
Active Contributor
0 Kudos

Hi Agata.

To provide further feedback it would be helpful if you posted the actual code you are using in the On Click script.

Also, could you clarify what you mean by "it resets the variables each time"?

Regards,

Mustafa.