Showing posts with label trick. Show all posts
Showing posts with label trick. Show all posts

Tuesday, March 27, 2012

Embedded code: what's the trick?

I am trying to put some embedded Visual Basic code into my report (RS 2005), using the "Code" section in the report properties.

Here's the function I'm trying to use:

Public Shared Function ReportTotal(ByVal IsUnitCost As Boolean,ByVal TotalDirectCosts As Double, ByVal SalaryBenefitsTotal As Double, ByVal IndirectRate As Double, ByVal SS_Screened As Integer, ByVal UnitRate As Double) As Double
If IsUnitCost Then
Return SS_Screened * UnitRate
Else
Return TotalDirectCosts + SalaryBenefitsTotal * IndirectRate
End If
End Function

Supposedly, after entering this you can access it in the expression for a field by typing the following: =Code.ReportTotal(... parameters ...)

However, when I try this, "ReportTalk" does not show up in the intellisense after I type "Code.". If I type it in anyway, a red squiggly line shows up under it, and if I attempt to preview the report, I get the following error: "The definition of report [report name] is invalid. Exception of type 'Microsoft.ReportingServices.ReportProcessing.ReportProcessingException' was thrown."

This is not a very helpful error message! I tried with and without "Public" and "Shared" and got the same thing.

What am I doing wrong?


Unfortunately, Custom code is not compiled until the report is published, so any custom methods will not show up in intellisense or be resolved (which results in the red underline) by the report designer.

If you are using RS 2005, then it should be evident in the exception message if the custom code generated the error. So, inorder to help you debug the issue I have a few questions:
What version of Reporting Services are you using?|||

Oh OK, you are right -- when I deploy the report, my code does work! Thank you very much.

You'd think there would be ONE mention of this little fact in SOME documentation, somewhere! It never would have occurred to me that the error was occurring only on preview.

In the SQL Server books online, the following is the entire entry for How to Add Code to a Report:

1. On the Report menu, click Report Properties.

Note: If the Report menu is not available, click within the report design area.

2. On the Code tab, in Custom code, type the code.

I kid you not. Anyway, thank you very much!

Embedded Code: whats the trick?

OK, I give up -- I can't get this to work. I am trying to put the following function into my report (RS 2005):

Public Shared Function ReportTotal(ByVal IsUnitCost As Boolean,ByVal TotalDirectCosts As Double, ByVal SalaryBenefitsTotal As Double, ByVal IndirectRate As Double, ByVal SS_Screened As Integer, ByVal UnitRate As Double) As Double
If IsUnitCost Then
Return SS_Screened * UnitRate
Else
Return TotalDirectCosts + SalaryBenefitsTotal * IndirectRate
End If
End Function

Supposedly, to use this code you put something like this for the expression in one of your fields: =Code.ReportTotal(...paramaters...)

However, when I type in "Code.", "ReportTotal" is not in the list provided by the Intellisense. If I type it in anyway, there is a red squiggly line under "ReportTotal", and then if I try to preview the report, I get an error: "The definition of report [report name] is invalid. Exception of type 'Microsoft.ReportingServices.ReportProcessing.ReportProcessingException' is thrown".

Real helpful. Does this mean there's an error in the Visual Basic? I tried to access the function improperly? What?

I tried with and without "Public", with and without "Shared". Same result.

Can anyone help??

I'm not familiar yet with 2005, but in 2000, there is a tab in the 'Report Properties' dialogue under the 'Report' menu.

If you put the code in there, IE:

Function FormatDateInterval(ByVal value As DateTime) As String
Return Year(value) & "-" & Month(value)
End Function

You can call the function by using something like:

= Code.FormatDateInterval(First(Fields!SaleDate.Value, "Foreclosures"))

Like I said, it works well in 2000. Hope it helps.

|||

Actually I found the answer. My code was fine -- it just doesn't get compiled until you deploy the report. I was testing it out in "preview" mode, and that's why it wasn't working.

Needless to say, this little feature is not documented anywhere!

sql

Embedded code: what's the trick?

I am trying to put some embedded Visual Basic code into my report (RS 2005), using the "Code" section in the report properties.

Here's the function I'm trying to use:

Public Shared Function ReportTotal(ByVal IsUnitCost As Boolean,ByVal TotalDirectCosts As Double, ByVal SalaryBenefitsTotal As Double, ByVal IndirectRate As Double, ByVal SS_Screened As Integer, ByVal UnitRate As Double) As Double
If IsUnitCost Then
Return SS_Screened * UnitRate
Else
Return TotalDirectCosts + SalaryBenefitsTotal * IndirectRate
End If
End Function

Supposedly, after entering this you can access it in the expression for a field by typing the following: =Code.ReportTotal(... parameters ...)

However, when I try this, "ReportTalk" does not show up in the intellisense after I type "Code.". If I type it in anyway, a red squiggly line shows up under it, and if I attempt to preview the report, I get the following error: "The definition of report [report name] is invalid. Exception of type 'Microsoft.ReportingServices.ReportProcessing.ReportProcessingException' was thrown."

This is not a very helpful error message! I tried with and without "Public" and "Shared" and got the same thing.

What am I doing wrong?


Unfortunately, Custom code is not compiled until the report is published, so any custom methods will not show up in intellisense or be resolved (which results in the red underline) by the report designer.

If you are using RS 2005, then it should be evident in the exception message if the custom code generated the error. So, inorder to help you debug the issue I have a few questions:
What version of Reporting Services are you using?|||

Oh OK, you are right -- when I deploy the report, my code does work! Thank you very much.

You'd think there would be ONE mention of this little fact in SOME documentation, somewhere! It never would have occurred to me that the error was occurring only on preview.

In the SQL Server books online, the following is the entire entry for How to Add Code to a Report:

1. On the Report menu, click Report Properties.

Note: If the Report menu is not available, click within the report design area.

2. On the Code tab, in Custom code, type the code.

I kid you not. Anyway, thank you very much!