Share via


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

Applies to: apps for SharePoint | SharePoint Server 2010

In this article
Return Value
Remarks
Example

Sets a single value for a workbook parameter, or sets a Multiple Items parameter that is based on a PivotTable, or sets filters on slicers.

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

Parameters

parameters

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

callback

The function that is called when the asynchronous operation is completed.

userContext

An object provided as a way for callers to pass state through the asynchronous call.

Return Value

None.

Remarks

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.

The method takes an array object that contains a key/value pairing as the first parameter. The key in the key/value pairing is a string that specifies the name of the workbook parameter or the name of the slicer. The value contains one or more strings that specify the value you want to set for a parameter or the filters that you want to set for a Multiple Items parameter or slicer.

Example

The following code example adds a button to the page and then adds an event handler to the button onClick event that sets a single value for the specified workbook parameter, "MyParameter". The success code for the asynchronous operation is then displayed in the browser status bar.

<script type="text/javascript">  
  
var ewa = null;
    
if (window.attachEvent)
{ 
    window.attachEvent("onload", PageLoad); 
} 

// Proceed to getEwa function once the Excel Services JavaScript OM is 'ready'.
function PageLoad() 
{         
    Ewa.EwaControl.add_applicationReady(getEwa); 
} 
       

 function getEwa()
{        
    // Get a reference to the Excel Services Web Part.
    ewa = Ewa.EwaControl.getInstances().getItem(0);        
}
    
function SetParamsAsyncButton()
{
    var objCollection = {};
    // Set the value of the workbook parameter, 'Name'.
    objCollection['MyParameter']= ['John Doe'];
    ewa.getActiveWorkbook().setParametersAsync(objCollection, SetParamsAsyncCallback, null);
}
    
function SetParamsAsyncCallback(asyncResult)
{
    // Display the success/failure code in the browser status bar.
    window.status = asyncResult.getCode();
}

</script>
<input type="button" id="SetParamsAsync" value="Set Parameters" onclick="SetParamsAsyncButton()" />

The following code example shows how to set more than one filter on the Excel slicer with the name "Slicer_Region". The slicer is set to filter on 2 values, "Ontario" and "Alberta".

<script type="text/javascript">  
  
var ewa = null;
    
if (window.attachEvent)
{ 
    window.attachEvent("onload", PageLoad); 
} 

// Proceed to getEwa function once the Excel Services JavaScript OM is 'ready'.
function PageLoad() 
{         
    Ewa.EwaControl.add_applicationReady(getEwa); 
} 
       

 function getEwa()
{        
    // Get a reference to the Excel Services Web Part.
    ewa = Ewa.EwaControl.getInstances().getItem(0);        
}
    
function SetParamsAsyncButton()
{
    var objCollection = {};
    // Filter on 'Ontario' and 'Alberta' in slicer, 'Region'.
    // Value in key/value pair contains 2 strings in order to set two filters.

    objCollection['Slicer_Region'] = ['Ontario', 'Alberta'];
    ewa.getActiveWorkbook().setParametersAsync(objCollection, SetParamsAsyncCallback, null);
}
    
function SetParamsAsyncCallback(asyncResult)
{
    // Display the success/failure code in the browser status bar.
    window.status = asyncResult.getCode();
}

</script>
<input type="button" id="SetParamsAsync" value="Set Parameters" onclick="SetParamsAsyncButton()" />

See Also

Reference

Ewa.Workbook Object

Other Resources

Change workbook parameters in a workbook in the browser

Filter items in a PivotTable report