on 01-06-2017 2:58 PM
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Have you run profiling - see https://blogs.sap.com/2015/06/30/understanding-profiling-and-statistics-in-design-studio/
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Poovarasan,
It's not that simple 🙂 I can't getData code on background because my application needs to be flexible. I mean, initially it does just that to pre-populate the dashboard with 12mths worth of stuff. But it needs to be flexible. In this example, the user uses dropdown box to select time period for which he wants to view the data (financial year, 12mths, this month, last month) - I then use GetMembers to select all members of the 0PROJECT dimension and for each member I update their corresponding text & chart. I use arrays to achieve this, and it's got to be very flexible. But my getMembers or getData don't get updated after the variables are changed - the DS takes too long to refresh.
I can't use data binding for the very same reason. All my items change constantly so can't be statically data bound.
User | Count |
---|---|
94 | |
11 | |
11 | |
10 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.