Skip to Content
0

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

Jan 06, 2017 at 02:58 PM

72

avatar image

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

10 |10000 characters needed characters left characters exceeded

Have you reviewed this blog on getData by Alfred Lee? https://blogs.sap.com/2015/09/10/a-study-of-getdata-getdataasstring-method/

0

Thanks Tammy, but unfortunately, the blog does not seem to address my problem. My problem is that the second line of my code which GetsData is triggered before the first line finishes refreshing my DS. I don't quite understand why this is happening...

0

HI Lukas,

Did you tried DS.reloaddata();

Thanks,

Varun

1
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Poovarasan Boopalan Jan 06, 2017 at 04:13 PM
0

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

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

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.

0

Sorry, what do you mean by "call the background processing in dropdown selection of period."?

0

Hi Lucas,

In Design studio application property you can write code to run in application background.

You can write your code there and call using code Application.doBackgroundProcessing();

Thanks,

Poovarasaan

0
Agata L. Jan 06, 2017 at 04:44 PM
0

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.

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

It does work, but taking ages to reload DS. I wonder if the query uses cache at all? But anyway, I think the problem solved. Thank you both for your help.

0
0

Thank you, that's a very useful read!

0
Mustafa Bensan Jan 09, 2017 at 10:26 AM
0

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.

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

That's a good idea. Not entirely great as I would rather have all my script in one place, but definitely worth considering.

Thank you.

Agata

0

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.

0