#1 2014-08-18 01:04:45

marcosfilho
Member
Registered: 2014-08-04

Validate parameters

Hello,

I have a created a report and it has some parameters. However I would like to make some of the parameters required.

Like:

Parameter 1*: required
Parameter 2: not required

Is there anyway I can make this happen?

I'm using ReportServer 2.2


Marcos

Offline

#2 2014-08-18 22:47:58

Thorsten J. Krause
Guest

Re: Validate parameters

Hi Marcos,

ReportServer has no concept of optional/required parameters, sll parameters must always have a value.
But depending on the parameter type parameters may appear as optional to the user because
    * the default value is used
    * an empty value is accepted

With a data driven parameter add an EMPTY value and make it the default to make the parameter optional. Without the explicitly empty value the user has to make a selection in order to not use the wrong value, so the parameter is mandatory.

With a text parameter you can specify a pattern (as a regular expression) the value must match. If you disallow empty values the parameter is required, otherwise it's optional.

Cheers,
Thorsten

#3 2014-08-18 23:34:12

marcosfilho
Member
Registered: 2014-08-04

Re: Validate parameters

Hi Thorsten,

Thanks for replying.

I understand the concept of data driven parameter. I believe it can work most of the time. What can cause problems for our users are dates. For example, imagine we have 2 date paremeters: startDate and endDate. We need to make sure that the endDate is greater than the startDate. I will discuss this with my team. But thanks for explaning.


Another question about the parameters: Is there any way I can create text parameters (not DataSource parameters) as radion buttons?

Thanks,

Marcos

Offline

#4 2014-08-18 23:46:43

Thorsten J. Krause
Guest

Re: Validate parameters

Hi Marcos,

unfortunately there is no validator that checks a parameter with respect to other parameters. If this is essential you could take a look at the script parameters. This allows you to use javascript to render your parameter and you could then implement a custom date-range component that performs these checks.

Checkboxes/Radio Buttons only work in conjunction with the datasource parameter. But you could create a CSV-Datasource with the "Argument Connector". If you do this and use the datasource with your parameters you can than specify the parameter values as csv in the parameter configuration.

Cheers,
Thorsten

#5 2014-08-19 00:22:36

marcosfilho
Member
Registered: 2014-08-04

Re: Validate parameters

Thanks again. I will look into the script parameters. Do you have an example? is this information available in the admin-guide?

Also the CVS workaround can work for us. Thanks.

Offline

#6 2014-08-19 00:39:02

Thorsten J. Krause
Guest

Re: Validate parameters

We are still in the process of updating the documentation to include all the changes introduced with RS 2.2.
So it's not in there, yet, but it will be with the release of 2.2.

I can give you a small example of a simple script parameter

#html
<!DOCTYPE html>
<html>
<head>
  <link rel="stylesheet" href="../resources/js/leaflet/leaflet.css" type="text/css" />
  <link rel="stylesheet" href="../resources/js/leaflet/leaflet.draw.css" />
  <script src="../resources/js/leaflet/leaflet.js" type="text/javascript"></script>
  <script src="../resources/js/leaflet/leaflet.draw.js" type="text/javascript"></script>
</head>

<body screen_capture_injected="true">
  <div id="map" style="width: 600px; height: 400px;" ></div>

  <script type="text/javascript">
  	var callback;
	function initParameter(param, cb){
		callback = cb;
	}
    var map = L.map('map').setView([50.0600, 8.3110], 11);
	var tiles = 'https://{s}.tiles.mapbox.com/v3/{id}/{z}/{x}/{y}.png';
	L.tileLayer(tiles, {
		maxZoom: 18,
		attribution: '',
		id: 'examples.map-20v6611k'
	}).addTo(map);

	var drawnItems = new L.FeatureGroup();
	map.addLayer(drawnItems);

	var drawControl = new L.Control.Draw({
		draw: {
			position: 'topleft',
			polygon: false,
			polyline: false,
			circle: false, 
			marker: false
			},
			edit: false
		});
	map.addControl(drawControl);
	map.on('draw:drawstart', function(e){
		drawnItems.clearLayers();
	});

	map.on('draw:created', function (e) {
		var type = e.layerType,
			layer = e.layer;

		var bounds = layer.getBounds();
		var res = (bounds.getSouthWest().lng + " " + bounds.getSouthWest().lat + ", " + bounds.getNorthEast().lng + " " + bounds.getNorthEast().lat);

		callback(res);
		drawnItems.addLayer(layer);
	});
  </script>
</body>
</html>

This example renders a map from openstreetmap and allows the user to select coordinates by drawing a rectangle.
the #html marks the script as to be returned as-is without looking for groovy code
the initParameter(param, cb) function  is called by when the parameter is added to the view. To register a new parameter value with ReportServer your code has to call the passed callback.

If you upload this script into the fileserver/bin directory you can select it from a script parameter in your report.

Cheers,
Thorsten

#7 2014-08-19 00:41:01

Thorsten J. Krause
Guest

Re: Validate parameters

This uses leaflet.js (http://leafletjs.com/) so to actually test the code you have to download the required libraries and add them to the appropriate directory.

#8 2014-08-19 01:12:20

marcosfilho
Member
Registered: 2014-08-04

Re: Validate parameters

Thanks, Throsten. You are the best.

I will look into this.

Marcos

Offline

Board footer

Powered by FluxBB