SSRS Parameter Specify Values - Expression Not Working - reporting-services

In SSRS, I am trying to use an expression to specify the available value for a text box parameter. I have tried several different things but my text box never gets populated with data. For the purpose of this post I have made the expression as simple as possible. Below is an example. The parameter is defined as single-value, non-blank, non-null, and visible.
Custom Code:
Public Shared Function TestFunc() as String
return "test"
End Function
Parameter Label: =Code.TestFunc()
Parameter Value: =Code.TestFunc()
In this simple example I would expect the text box parameter to have the value 'test' but this is not the case. What am I missing here? Is there a different syntax or a setting that I'm unaware of?

Related

Type Mismatch (Error 13) when populating a null field in VBA

I'm trying to populate a control from an external form with a string value on button click - this is working perfectly when there is already existing text, however if there is nothing then it is treated as a null value and therefore returns a Type Mismatch error.
I thought I would be able to work around this by using:
Nz(Forms!frmSpecifications!boxScratchpad.value, "") = "Text string"
But this hasn't worked.
Could it be to do with how I am calling the control, or the properties of the control itself?
UPDATE: After looking into this a bit more I have pinpointed the issue to a SQL query execution earlier in the code which runs an update statement on the same table that boxScratchpad normally gets its data from (although the field which is fed into boxScratchpad is not actually updated). If I comment out this code so that the update statement doesn't run, boxScratchpad populates successfully. It seems like there could be a conflict between the table being updated and boxScratchpad being assigned a new value within the same code?
First of all, understand what you are trying to accomplish and what your code does.
Assuming your control is a textbox, the property that displays its text is value. If your control is a button, the property that displays text is caption.
You are trying to assign a string to this control value or caption, there will be no issues if those properties are currently NULL.
The mistake lies within the nz. If nz evaluates your control's property to NULL, it will return your empty string as the answer, thus ending in this situation:
"" = "Some text"
Which will throw error "It requires an object".
Remove the nz function.
To really test the interference of your SQL update with the control, use the inmediate window in vba editor to execute and test your code.

What's up with SSRS parameters and images?

I'm working on setting up a report in SSRS. Our report is somewhat flexible, and I'm looking to dynamically select an image for a cover page based on a parameter.
Here's what I have:
In our Reports db I have an image table set up. To keep things simple, lets just say I have three columns:
ImageName, ImageType, and Image.
Name and type are both varchar while ImageType is varbinary. I've uploaded the images we plan on using as well as their names and associated types to the table.
In my report I have a Data Source and a Dataset for bringing in the above table and columns.
I also have a parameter called "ImageName." I've set this parameter up to use "Image" (from the table described above) as its value field and the label field is set up for "ImageName."
On the report itself I have an image ... control? Report element? Not sure what to call it, but I've set up an image. The image source is set to "Database" and the MIME type uses the lookup function to pull the appropriate image type from the Dataset based on the Parameters!ImageName.Label argument - and that part works a treat - I'm returning the proper MIME type each time.
What doesn't work, and I would expect should work, is setting the image itself. For the "Use this field" field under "Select the image source:" I've tried both =Parameters!ImageName.Value with no success as well as a lookup based on the ImageName.Label from the images Dataset. Neither seem to work.
When I try using the parameter value, I'm getting the error
[rsInvalidDatabaseImageProperty] The value of the ImageData property
for the image 'ImageControlName' is "=Parameters!ImageName.Value",
which is not a valid ImageData.
I get essentially the same error message from the lookup method, it just swaps the lookup code for the Parameters!ImageName code above.
If I attempt to check the type returned by the lookup above I simply get an error. For the parameter if I check the type I get System.String so I decided to print that out and apparently the value of Parameters!ImageName.Value is System.Byte[] for some reason.
I can get an image to display using the First() function, but I need to be able to select the image. I'm guessing I may have to filter. First() has a return type of System.Byte[], which seems reasonable. I just don't understand why my parameter is returning the type of the image data column as a string rather than the data from the image column itself.
So how do I get this working? Is filtering my Dataset my only option? Or is there a way to get the parameter working or to get some function that will allow me to select the appropriate image?
Reason for your error is because of the data types returned by Parameters vs First.
For the Parameters data type returned is of type text and which is not valid image data type hence the error.
For First function it returns the data type based on type of expression and it returns the right type of data type for image and displays the image.
Per Microsoft Parameter Data Type:
A report parameter must be one of the following data types:
Boolean. The user selects True or False from a radio button.
DateTime. The user selects a date from a calendar control.
Integer. The user types values in a text box.
Float. The user types values in a text box.
Text. The user types values in a text box.
When available values are defined for a parameter, the user chooses
values from a drop-down list, even when the data type is DateTime.
Per Microsoft First function data type:
Return Type
Determined by the type of expression.
You are correct to get the right image you need to filter the dataset.
Create dataset which gives ImageName, ImageType, and Image.
Based on image parameter filter the dataset on ImageName.
Now use the following expression to get the correct image data.
=Fields!Image.Value

SSRS limiting number of characters for a parameter

How can I limit the number of characters a user can type for a parameter in SSRS?
For example, if the Data Type is set to TEXT, how to limit the user to type only 6 characters after Default value of "CL/" OR limit to total of 9 characters.
Unfortunately you can't perform validation as people write values, you can only handle them when the report is run. You can however use Code behind the report to perform some validation on your Parameters at run-time. Based on the result of this you can then either display the required data to instead return an error message.
To insert some code behind you right click the area around the report, Choose Report Properties, then Code.
Enter something like this into the code panel
Function Validate(param) as Boolean
If len(cstr(param)) <= 9 Then
Return"True"
Else
Return "False"
End if
End Function
You can then refer to the result of this from a text box that displays an error as follows
Right click the text box and set the visibility to be
=iif(Code.Validate(Parameters!myInput.Value) = True, True, False)
Then if you enter a string of 9 or fewer characters you will get an error that you can use to inform the user of the proper format of your desired input string.
Instead of just making text boxes visible/invisible, you could also apply this to rectangles that store your report information. Also, you can use visual basic coding to alter the Code behind to perform more complicated parameter validation to check for you "CLI" string for example.
I hope this helps, let me know if you require further help.

LIKE operator in SSRS row visibility expression

I have a text box within an rdl report which I want to suppress based on certain terms in my dataset (i.e. if the query returns a term which ends with the letter "L" then hide the text box).
Within the textbox properties I have set visibility expression for Hidden with the below expression:
=First(Fields!STERMS__.Value, "Job") NOT LIKE '%L'
When I run it I get the error:
"The Visibility.Hidden expression for the text box contains an error:
[BC30201] Expression expected"
It seems like a schoolboy error but I have tried various permutations on this expression with no luck. Any help would be appreciated.
SSRS expressions are funny in some ways. I think what you're looking for is:
=IIf(First(Fields!STERMS__.Value, "Job") Like "*L", True, False)
The gist is that SSRS doesn't use SQL syntax. It's VB
I think you could use the Right() function which returns a specified number of characters from the right hand side of a string.
E.g.
=Right(Fields!STERMS__.Value,1)
I guess in your case for Hidden property on the cell, the expression would look like this
=IIF(Right(First(Fields!STERMS__.Value, "Job"),1)=="L",true,false)

SSRS expression replace NULL with another field value

I need to write an SSRS expression to check and replace NULL field value with another field value. Can this be done?
=iif(isNothing(Fields!FV1.Value), Fields!FV2.Value, Fields!FV1.Value)
If you have to do it a bunch of times, you can also make a reusable function to avoid a lot of typing. Here's a solution modeled off of SQL's ISNULL function:
Right click on the Report Document and go to Report Properties.
Navigate to the Code tab and add the following function:
Public Function IsNull(input As Object, defaultValue As Object) As Object
Return IIf(input Is Nothing, defaultValue, input)
End Function
Note - Even though the custom code is expecting valid VB.NET code, you have to use the IIF Ternary operator.
Then you can use it in an expression like this:
=Code.IsNull(Fields!MyField.Value,0)