Pass Parameters to a Report

Please see my other Telerik report articles.

Display Current Windows Username

In this article I’ll demonstrate how to display the Windows username of the current user of a report.
I’ll start by using the report’s ReportParameter’s editor to add a single Parameter “UserName”.

This addition not only is required to display the property in the report, but provides access to it within the Expression Editor (next step)
Next, I’ll add an HTML textbox and use its Expression Editor to access the report’s parameters to display the UserName.

Note: Since I used an HTML textbox instead of a regular textbox, I am able to provide HTML markup around my data for styling and layout.

Also, notice in the Expression Editor when I click the ReportParameters icon, the UserName parameter is accessible due to my work in the last step.

Next, I’ll create a custom function for use anywhere in my application which allows me to retrieve the current user’s Windows username and use my custom Db table to translate it into the user’s first and last name.

If the user doesn’t yet have their names in the table, the Windows username is returned.

With my report ready, now I’ll deploy it to my report server.

Next, I’ll prepare my application to serve the report by updating my controller with a new action to call the report.

Note in the action is a call to my custom function which retrieve the current user’s Windows username and stores it in Session memory.

Next, I’ll create a new Telerik MVC Report Viewer View and in it pass to the report my Username report and its value from Session memory.

Now I’m ready to run the report and see my Windows username translated into my first and last name.