Setting the parameters in JavaScript Web Viewer

 

To be able to work with parameters in SharpShooter Reports.Web a reportViewer.parameters property should be used.

This property represents a collection of values of PerpetuumSoft.Reporting.WebViewer.Model.ParameterModel type.

PerpetuumSoft.Reporting.WebViewer.Model.ParameterModel consists of the following fields:

 

Name

Parameter name

Value

Parameter value

Type

Parameter type ( should belong to one of the.NET types)

DefaultValue

The value used by default. In case the parameters are pre-loaded from server side the default value is set.

 

Thus, the final code for specifying the parameter looks as follows:

var parameter = new PerpetuumSoft.Reporting.WebViewer.Model.ParameterModel();

parameter.Name = "<parameter name>";

parameter.Value = <parameter value>;

parameter.Type = "<parameter type>";

parameter.DefaultValue = <parameter default value>;

reportViewer.parameters.add(parameter);

 

Note:  Avoid using the same parameter name for several parameters since this will result in ignoring one of the values.

 

If you are using an outdated product version (released prior to ver. 7.0) it is necessary to take into consideration the following details:

 

1) All specified properties should be set in order to avoid a “Property not found” error

2) When setting the property of the ‘string’ type it is necessary to wrap the string by additionally using internal quotation marks.

   Besides, the JSON-compliant escape sequence should be used for the string itself.  

 

For example:

parameter.Name = ‘”Some value \\\\ ”’; //Some value string\


The version 7.0 introduces more convenient and simple approach for work with parameters.

1) There’s no need to convert the string values. A user can simply set the string value and it works as expected (the use of escape sequence is no longer needed as well)

For example:

parameter.Name = ”Some value  \\”; // Some value string\

2) To be able to add a parameter it would be enough to set only two properties: parameter name and its value. The parameter type would be set automatically according to the value. Unfortunately this feature is available only for simple types, such as string, integer and Boolean. The type should be manually specified for parameters of other type. Specifying the DefaultValue is optional.

3) The following functions were added to simplify the process of setting the parameters:

 

Function

Description

Example

setParameter(

  <parameter name>,

  <parameter value>)

Sets the parameter value. Performs the search for parameter with the specified name, and in case the parameter is found, the new value is set; else a new parameter with the specified name and value is added.

The type would be automatically set for string, integer and Boolean. To specify the rest of the types the

SetTypedParameter method should be used.

reportViewer

  .setParameter(

    ‘MyParameter’,

    10);

setTypedParameter(

  <parameter name>,

  <parameter type>,

  <parameter value>)

Sets the parameter value and its type. Performs the search for parameter with the specified name, and in case the parameter is found, the new value and type is set; else a new parameter with the specified name, type and value is added.

reportViewer

 .setTypedParameter(

    ‘Date’,

    ‘System.DateTame’,

    new Date(2013, 2, 1))

getParameter(

  <parameter name>)

Performs the search for parameter with the specified name, and in case the parameter is found, it returns a function; else null is returned.

var parameter =

 reportViewer

  .setTypedParameter(

    ‘Date’);

 

Add Feedback