Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSRS Set Parameters programmatically causing to state ValidValueMissing

I'm trying to get the parameter of user name and replace its value with the session's username so I can pass to a Stored procedure inside the DRL to generate a table timestamp with this user name. The parameter "username" is one of the parameters of the RDL which comes with default value and I'm trying to change it with the following code.

Replacing one of the ReportParameters:

var userParameter = GetUserParameter();
if (userParameter != null)
{
    newParameters.Remove(newParameters.FirstOrDefault(param => param.Name.Contains(CurrentUserParameterName)));
    newParameters.Add(userParameter);
}

Finding username ReportParameters:

var paremeters = ReportViewer.ServerReport.GetEditableHiddenParameters();

//finds parameter by its name, pelase view const value in CurrentUserParameterName
var userParameter = paremeters.FirstOrDefault(param => param.Name.Contains(CurrentUserParameterName));
if (userParameter != null)
{
    userParameter.Values.Clear();
    userParameter.Values.Add(Utils.GetUserName());
}
return userParameter;

Set Parameters to ServerReport:

ReportViewer.ServerReport.SetParameters(parameters);

After running the report, I get the message "The 'username' parameter is missing a value"

When I debug and look in the ServerReport.GetParameters() I can see that I do have the ReportParameter "username", I do have values (the new values), but its State is "MissingValidValue".

What am I doing wrong? Thanks in advance, Eddie

like image 836
Eddie Rozenblat Avatar asked Sep 11 '11 07:09

Eddie Rozenblat


1 Answers

I've finally managed to fix this issue thanks to this article: http://technet.microsoft.com/en-us/library/dd220464.aspx

If you have specified available values for a parameter, the valid values always appear as a drop-down list. For example, if you provide available values for a DateTime parameter, a drop-down list for dates appears in the parameter pane instead of a calendar control. To ensure that a list of values is consistent among a report and subreports, you can set an option on the data source to use a single transaction for all queries in the datasets that are associated with a data source.

Since I entered a default value in the "available values" option in addition to putting it in the "default values", the report tried to validate the new session username, which wasn't listed as an "available value". Once I removed the values in "available values", the new ReportParameter that I supply in code-behind didn't have to be validated, and the report rendered successfully.

like image 163
Eddie Rozenblat Avatar answered Oct 20 '22 06:10

Eddie Rozenblat