Skip to Content
0

DS.loadDataSource() ignores Variable Initialization

Jan 11, 2017 at 05:04 PM

263

avatar image
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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

6 Answers

Best Answer
Koen Hesters Jan 18, 2017 at 12:21 PM
0

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.

Show 4 Share
10 |10000 characters needed characters left characters exceeded
Former Member

So I do the following:

if (state = 0) {

DS.loadDataSource();

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

state = 1;}

Is that correct? Thanks!

1

state == 0

but yeah that's the idea

0
Former Member
Koen Hesters

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.

1

:) thanks! happy designing :)

0
avatar image
Former Member Jan 12, 2017 at 01:22 AM
0

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

Share
10 |10000 characters needed characters left characters exceeded
Mustafa Bensan Jan 11, 2017 at 11:19 PM
0

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.

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Jan 12, 2017 at 01:19 PM
0

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.

Show 2 Share
10 |10000 characters needed characters left characters exceeded

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

0
Former Member
Koen Hesters

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?

0
avatar image
Former Member Jan 18, 2017 at 10:15 AM
0

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

Show 5 Share
10 |10000 characters needed characters left characters exceeded
Former Member

>>> 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.

0
Former Member
Former Member

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

0
Former Member
Former Member

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.

0

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

1
Former Member
Giulia Sogaro

Perfect!

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

0
Giulia Sogaro Jan 18, 2017 at 02:59 PM
0

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

Show 1 Share
10 |10000 characters needed characters left characters exceeded
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.

1