Skip to Content
avatar image
Former Member

DS.loadDataSource() ignores Variable Initialization

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

6 Answers

  • Best Answer
    Jan 18, 2017 at 12:21 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded

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

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 11, 2017 at 11:19 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 12, 2017 at 01:19 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded

    • 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?

  • Jan 18, 2017 at 10:15 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 18, 2017 at 02:59 PM

    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

    Add comment
    10|10000 characters needed 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.