logo

Warning: The forum is now for consultation only. Please use GitHub Discussions to post any questions or comments.


Welcome Guest ! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
prol  
#1 Posted : Tuesday, February 21, 2017 8:57:04 PM(UTC)
prol

Rank: Newbie

Groups: Registered
Joined: 9/8/2016(UTC)
Posts: 8
Brazil
Location: Caxias do sul

Thanks: 2 times
Hi!

I need to filter my enumerated lists based on the current user, is there a way to use Environment.UserName with the SQL query?

Thanks!
epf  
#2 Posted : Wednesday, February 22, 2017 10:33:05 AM(UTC)
epf

Rank: Administration

Groups: Administrators
Joined: 12/20/2013(UTC)
Posts: 1,209
Switzerland

Thanks: 14 times
Was thanked: 206 time(s) in 199 post(s)
Good question,

here is how to do it with the 3.0:
Select your root view and edit the 'Init Script' where you can modify your report definition before it is being rendering...

Code:
    var source = report.Sources.FirstOrDefault(i => i.Name == "Northwind (Repository)");
    if (source != null) {
		var enumList = source.MetaData.Enums.FirstOrDefault(i => i.Name == "Last Name");
		if (enumList != null) {
			report.LogMessage("Refreshing Enum values...");
			var userName = report.SecurityContext != null ? report.SecurityContext.Name : "No context";
			enumList.Sql = string.Format("select LastName, '{0}-' + LastName from employees", userName);
			enumList.RefreshEnum();
		}
	}


This code select an enum list from a source, then it updates its Sql Statement and finally refresh the values...
The SecurityContext allows you to get the login name got from the Web Report Server, you can of course change the SQL with a where clause having Environment.UserName.

In 3.1, you will be able to add this code directly in the Enum definition, so it can defined in the repository source and applied to all reports...
thanks 1 user thanked epf for this useful post.
prol on 2/22/2017(UTC)
prol  
#3 Posted : Wednesday, February 22, 2017 2:38:06 PM(UTC)
prol

Rank: Newbie

Groups: Registered
Joined: 9/8/2016(UTC)
Posts: 8
Brazil
Location: Caxias do sul

Thanks: 2 times
Thank you epf, it worked!

Good to know about 3.1.
Users browsing this topic
Guest (2)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.