0

The setParametersAsync method takes a JavaScript object as it's first parameter. When I pass a literal object with a single value assigned to a key, the method calls it's callback function, executing successfully:

obj = {Slicer_Grade_Level:"11"}
ewa.getActiveWorkbook().setParametersAsync(obj, setParametersAsyncCallback, null)

When I pass a literal object with an array assigned to a key, the method fails to call it's callback function. No error is thrown, and the parameters are not applied to the workbook:

obj = {Slicer_Grade_Level:["11","12"]}
ewa.getActiveWorkbook().setParametersAsync(obj, setParametersAsyncCallback, null)

The workbook is hosted on a personal OneDrive cloud, not in a SharePoint library.

Any suggestions about this apparent limitation would be greatly appreciated.

SurvivalMachine
  • 7,946
  • 15
  • 57
  • 87

1 Answers1

0

The docs sais

Ewa.Workbook.setParametersAsync(parameters, callback, userContext);

Parameters

parameters

An array object that contains the values that you want to set.

...

So I'd say the correct usage would be:

obj = ["11"]
ewa.getActiveWorkbook().setParametersAsync(obj, setParametersAsyncCallback, null)

for one value and

obj = ["11","12"]
ewa.getActiveWorkbook().setParametersAsync(obj, setParametersAsyncCallback, null)

for 2 values.

I may be wrong, anyway I'd suggest to try also

obj = {Slicer_Grade_Level:"11",Slicer_Grade_Level2:"12"}
ewa.getActiveWorkbook().setParametersAsync(obj, setParametersAsyncCallback, null)
Community
  • 1
  • 1
YakovL
  • 7,557
  • 12
  • 62
  • 102
  • Your first two suggestions create javascript arrays, not objects. The example code on the microsoft page you cited above describes how to create a syntactically correct literal object as a key/value combination with an array as the value of a key. Your third example does create an object with two different key/value combinations, and would work. It doesn't address my original question, which is why assigning an array to the value of a key seems to cause an infinite loop (arrays are declared with square brackets [ ]). – Milton Robinson Oct 01 '16 at 22:25
  • To clarify, javascript arrays are special types of objects with numerical keys. Traditional javascript objects have string keys. – Milton Robinson Oct 01 '16 at 22:28
  • @MiltonRobinson I'm somewhat puzzled. I though "array object" means "instance" of `Array` (https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array), which *is* an object. What else could "array object" mean? – YakovL Oct 02 '16 at 18:33
  • But you're right, in the example `SetParamsAsyncButton` is set as you have shown in your original post. Is it important to set those numbers as strings? Have you tried `obj = {Slicer_Grade_Level:[11,12]}`? – YakovL Oct 02 '16 at 18:36
  • These links describe the differences between javascript objects () and javascript arrays (). Passing the parameters as numerical values doesn't change the behavior, but good suggestion. – Milton Robinson Oct 02 '16 at 22:25
  • @MiltonRobinson :D no-no, I know what javascript object is, but the docs sais "array object" and I don't have any idea to interpret this phrase anyhow different from "an `Array`-instantiated object" (`var obj = new Array(...);`). But probably they mean a hashmap or something like that. This may seem off-topic, but it *is* connected with how to use the function, so I'm trying to understand. – YakovL Oct 04 '16 at 09:42
  • By the way, how do you understand this remark from docs: "The `Ewa.Workbook.setParametersAsync` method can be used to set *a single value for a workbook parameter, the filters for a Multiple Items parameter that is based on a PivotTable, or the filter for a slicer.*"? – YakovL Oct 04 '16 at 09:42
  • I believe the microsoft documentation is abbreviated. The context of the statement 'Array Object' seems to refer to the filter values that are passed to the method: `["11", "12"]`. Since the method also needs to know the _name_ of the workbook parameter being filtered, an object is used whose keys correspond to the names of the workbook parameters (slicers in this case, but could be cell ranges or pivot tables): `obj["Slicer_Grade_Level"] = ["11", "12"]` or `obj = {Slicer_Grade_Level: ["11", "12"]}`. The parameter name and it's multiple filter values cannot be passed in a simple array object. – Milton Robinson Oct 05 '16 at 01:29