Skip to Content
avatar image
Former Member

DS.getData() does not show updated value after DS refresh with DS.setVariableValue().

Hiya,

I wonder if it's another bug in DS, or I'm doing something wrong. The DS.getData() does not show updated value after my DS is refreshed by DS.setVariableValue().

My DS is restricted by default by fiscal year variables 001.2017-012.2017. I use the following code to get the value for a particular measure and member:

var myValue = DS.getData("8XTGMGN8NEDHZYZLCDPMKX644",{"0PROJECT":someProject}).value;

The result is myValue=100 and I display it in a text box.

Then I want to use a dropdown box to change variables on the DS to 009.2017. OnClick code runs and does the following:

DS.setVariableValue("someVariable", "2017009");

var myValue = DS.getData("8XTGMGN8NEDHZYZLCDPMKX644",{"0PROJECT":someProject}).value;

I am expecting myValue to change to 5, and update the text box, but it still says 100. Why?

I have tried loading DS after setVariableValue using loadDataSource() but that did not help either: getData gets triggered before DS has a chance to update. And I can actually see it when I add an APPLICATION.alert(myValue) in my code - I can see the alert on screen immediately, while DS is still being refreshed in the background.

Is this a bug, or am I doing something wrong? I would have thought that the setVariableValue will refresh my DS and then getData will pick up correct value? Or do these two run asynchronously?

Thanks,

Agata

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Jan 06, 2017 at 04:13 PM

    Hi Lukas,

    It's may be because your data set is huge so it takes time to load data and script not getting correct value.

    Try get data code on background processing of application and set text to text box in background processing itself and call the background processing in dropdown selection of period.

    But the best way is to use data binding on text boxes. So you don't need to worry about scripting.

    Let me know if you need any help in it.

    Thanks,

    Poovarasan

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 06, 2017 at 04:44 PM

    I think I solved it!

    I added DS.reloadData() to the code after I change my variables and before I call getData.

    I will do a little testing and see if the solution stands.

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 09, 2017 at 10:26 AM

    Hi Agata,

    This could be a timing issue. Instead of placing your getData() call immediately after the setVariableValue() call, try putting the getData() call in the data source "On Result Set Changed" event script to ensure it is executed only after the data source has been fully refreshed by any actions that trigger a data source update.

    Regards,

    Mustafa.

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Agata,

      While it is certainly a best practice to consolidate code, it is also important to consider where the code needs to be triggered in the context of the scripting API. This is one example where you need to break the code apart but you can still implement a modular approach by placing all the code into global script functions.

      Regards,

      Mustafa.