getData is a very useful method. However, I found it a little bit more complex than I thought initially. Thus, I did some tests to understand its behaviors.
There are 3 notes described in the content assistant.
•This method specifies members in the internal format.
•For dimensions that are not specified, their aggregates will be used, provided that the corresponding aggregates exists in the result set.
•The requested data needs to be part of the retrieved result set. This is especially important when requesting hierarchy nodes. The hierarchy needs to be expanded in advance to show the required hierarchy node.
Besides these 3 points, I think the key idea is that getData is not really to query but just to search from result set. Thus, the wanted data cell must exist in the result set and must “logically” have only one corresponding cell (see Test 5). And getData will take whatever number from that data cell even if the value has been filtered (see Test 7).
Let's start from the simplest one.
Test 1:
Column: AMOUNT_SOLD
Row: Yr (with “Show Totals” checked)
DS_1.getData("AMOUNT_SOLD", {"YR": "2003"}).value
Result: correct result
Test 2 & Test 3 & Test 4:
Column: AMOUNT_SOLD
Row: Yr (with “Show Totals” checked), QTR (with “Show Totals” checked)
DS_1.getData("AMOUNT_SOLD", {"YR": "2003"}).value
Result: correct result
DS_1.getData("AMOUNT_SOLD", {"YR": "2003","QTR": "1"}).value;
Result: correct result
DS_1.getData("AMOUNT_SOLD", {"QTR": "1"}).value;
Result: no result
Test 5:
Column: AMOUNT_SOLD
Row: QTR (with “Show Totals” checked), MONTH_NAME (with “Show Totals” checked)
DS_1.getData("AMOUNT_SOLD", {"MONTH_NAME": "January"}).value;
Result: no result even though there is only one corresponding “January” data cell. All upper-level dimensions need to be specified in the selection
Test 6:
Column: AMOUNT_SOLD
Row: Yr (with “Show Totals” checked), QTR (with “Hide Totals” checked)
DS_1.getData("AMOUNT_SOLD", {"YR": "2003"}).value
Result: no result
Test 7:
Column: AMOUNT_SOLD
Row: Yr, QTR (Filter Members: “1”)
DS_1.getData("AMOUNT_SOLD", {"YR": "2003"}).value;
Result: The result value is the AMOUNT_SOLD of Year 2003, Q1 not whole year
Test 8:
If the result set is too large, then no data will be shown in the Result Set. Thus, getData won’t work even though we just need the value of one data cell.
One last thing.
Parameters of getData include “measure”, “dimension”, and “value for the dimension”. “Measure” and “value for the dimension” can be replaced by variable while “dimension” cannot. To solve this issue, we can use Design Studio SDK: JSON Object Component. (thank you Karol)
http://scn.sap.com/docs/DOC-63667
Without SDK:
var measure=”AMOUNT_SOLD”;
var year=”2003”;
DS_1.getData(measure,{"Yr":year}).value