WebDev Passing Parameters

Since there is apparently a bug in the Perspective Report Viewer component, Tech Support has suggested using the WebDeb module as a work a round.
I have to pass some parameters to my report (Start & End Dates as well as Track Name).
How are parameters passed into the WebDev Endpoint?

Currently my WebDev resource has the following code:

	rptParams = {'StartDate':'2020-06-10 00:00:00', 'EndDate':'2020-06-17 00:00:00', 'track':'Track 902'}
	
	return {'bytes': system.report.executeReport(path = 'Downtime', project = 'Core', parameters = rptParams, fileType = 'pdf')}

I have these parameters set statically for testing but they need to be passed in dynamically.

Thanks.

For a get request, the generally recommended way of adding additional information is via URL/query parameters [1]. That’s a standard web “thing”, and you have easy access to them in WebDev.
So, for a URL like:
http://localhost:8088/system/webdev/project/reports
You can add parameters to the URL like so:
http://localhost:8088/system/webdev/project/reports?startDate=2020-01-10%2000:00:00&track=Track%20902
Query parameters start at the ? and are key: value pairs, delimited by &. Parameters can be any value, but have to conform to the restricted subset of characters that are valid in a URL - so, for instance, spaces (and other symbols) get url/percent encoded [2].

In webdev, you access these parameters via the params…parameter (:slight_smile:), which is automatically supplied to your doGet implementation. All incoming parameters will be strings, because they have to be, so you’ll have to parse them into appropriate datatypes before submitting them to your report. You can do this for dates using system.date.parse, although I’d recommend just passing your dates in as millisecond values, then you can easily convert them back without messing around with specific format strings: [3].

All together, it would look something like:

rptParams = {
	'StartDate': system.date.fromMillis(int(params["StartDate"])),
	'EndDate': system.date.fromMillis(int(params["EndDate"])),
	'track': params["track"]
}
	
return {'bytes': system.report.executeReport(path = 'Downtime', project = 'Core', parameters = rptParams, fileType = 'pdf')
1 Like