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.

4
  • I'd suggest you to do your best making this shorter.. Commented Oct 1, 2016 at 13:52
  • 1
    I've compressed my original post. Commented Oct 1, 2016 at 15:04
  • Great! Also, a newline before your code will make formatting of the code work as expected Commented Oct 1, 2016 at 16:32
  • 1
    I've reformatted the code samples in my original post. Commented Oct 1, 2016 at 21:16

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

8 Comments

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 [ ]).
To clarify, javascript arrays are special types of objects with numerical keys. Traditional javascript objects have string keys.
@MiltonRobinson I'm somewhat puzzled. I though "array object" means "instance" of Array (developer.mozilla.org/en/docs/Web/JavaScript/Reference/…), which is an object. What else could "array object" mean?
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]}?
These links describe the differences between javascript objects (<w3schools.com/js/js_objects.asp>) and javascript arrays (<w3schools.com/js/js_arrays.asp>). Passing the parameters as numerical values doesn't change the behavior, but good suggestion.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.