Using an object as input to the CR Designer and runtime

I just succeeded in getting my first CR .rpt file built with the ADO.Net Dataset designer resulting in a nice tabular report at runtime (passing an ADO.Net dataset, rendering it as a PDF report, etc).
Now I need to find out how to fill out the Report Header and Page Header sections. At runtime, most all of the information I need for these sections is available to me in the Request.Form object.

Are there any good examples of how to model report sections at design time when the "data" for will not be available till runtime in some .Net object?

[562 byte] By [JohnJ.Adams] at [2007-12-16]
# 1
Hello John,

I would suggest placing formula fields in the header sections as place holders and then passing the value to them at runtime.

Setting a formula field value at runtime is covered in this kbase:

http://support.businessobjects.com/library/kbase/articles/c2010354.asp

You can also look for the dynamic report sample as it uses formula fields at runtime:

vbnet_win_dynamic_report_formula.zip

http://support.businessobjects.com/communityCS/FilesAndUpdates/vbnet_win_samples.exe.asp

Keith - Business Objects

KeithThomson at 2007-9-9 > top of Msdn Tech,Visual Studio,Crystal Reports for Visual Studio...
# 2
Thanks, Keith. I will have a look.
JohnJ.Adams at 2007-9-9 > top of Msdn Tech,Visual Studio,Crystal Reports for Visual Studio...
# 3
I am just getting back into this after sidetracking on other projects...
I added 1 formula (using Basic Syntax) to the report header section and it works fine when content is "static" as in:
formula = "Copyright 2005 by DAPDataWeb LLC"
The formula name is Disclaimer which Crystal shows as @Disclaimer.
Now I am trying to assign the value to the formula at runtime per guidelines mentioned above in this thread.
Dim oRpt As New MarketShareAuto_CrystalReport
oRpt.DataDefinition.FormulaFields.Item("Disclaimer").Text = "set formula at runtime"

Dim DiskOpts As CrystalDecisions.Shared.DiskFileDestinationOptions = New CrystalDecisions.Shared.DiskFileDestinationOptions
Dim sFolder As String = ConfigurationSettings.AppSettings("PDFWorkFolder")
Dim sUnique As String
sUnique = Session.SessionID
oRpt.SetDataSource(objDataSet)
oRpt.ExportOptions.ExportDestinationType = CrystalDecisions.[Shared].ExportDestinationType.DiskFile
oRpt.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat
DiskOpts.DiskFileName = sFolder & sUnique & ".pdf"
oRpt.ExportOptions.DestinationOptions = DiskOpts
oRpt.Export()
CrystalReportViewer1.ReportSource = oRpt
I set a breakpoint on the line above that assigns a value to the formula named Disclaimer and I got no runtime complaints. Instead it executes all the way down to the Export method then terminates with this:

Server Error in '/DAP3' Application.

Error in File C:\WINDOWS\TEMP\temp_38a4be10-5198-465b-aeae-bbda97b09bbe.rpt: Error in formula <Disclaimer>. 'set formula at runtime' The remaining text does not appear to be part of the formula.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: CrystalDecisions.CrystalReports.Engine.FormulaException: Error in File C:\WINDOWS\TEMP\temp_38a4be10-5198-465b-aeae-bbda97b09bbe.rpt: Error in formula <Disclaimer>. 'set formula at runtime' The remaining text does not appear to be part of the formula.

Source Error:

Line 95: DiskOpts.DiskFileName = sFolder & sUnique & ".pdf"
Line 96: oRpt.ExportOptions.DestinationOptions = DiskOpts
Line 97: oRpt.Export()
Line 98: CrystalReportViewer1.ReportSource = oRpt
Line 99:

Source File: c:\inetpub\wwwroot\DAP3\Out\MarketShare.aspx.vb Line: 97

Stack Trace:

[FormulaException: Error in File C:\WINDOWS\TEMP\temp_38a4be10-5198-465b-aeae-bbda97b09bbe.rpt:
Error in formula <Disclaimer>.
'set formula at runtime'
The remaining text does not appear to be part of the formula.]
. F(String , EngineExceptionErrorID
)
. A(Int16 , Int32 )
. @(Int16 )
CrystalDecisions.CrystalReports.Engine.FormatEngine.Export(ExportRequestContext reqContext)
CrystalDecisions.CrystalReports.Engine.FormatEngine.Export()
CrystalDecisions.CrystalReports.Engine.ReportDocument.Export()
DAP3.MarketShare.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\DAP3\Out\MarketShare.aspx.vb:97
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()


Version Information: Microsoft .NET Framework Version:1.1.4322.2300; ASP.NET Version:1.1.4322.2300

JohnJ.Adams at 2007-9-9 > top of Msdn Tech,Visual Studio,Crystal Reports for Visual Studio...
# 4
Hello,

When passing in a string value to Crystal Reports you need to pass in the quotes as well as the Crystal Reports formula editor requires the quotes.

So something like:

oRpt.DataDefinition.FormulaFields.Item("Disclaimer").Text = "'" + "set formula at runtime" + "'"

That is " ' " - this will concatenate together to pass in the quotes the formula editor needs.

Keith - Business Objects

KeithThomson at 2007-9-9 > top of Msdn Tech,Visual Studio,Crystal Reports for Visual Studio...
# 5
Hello.

this example is good, but when my string has a quote inside, I get an error

oRpt.DataDefinition.FormulaFields.Item("Disclaimer").Text = "'" + string + "'"

string= " This is Angel's Sample "

It does not work.

What I have to do?

AngelPalomino at 2007-9-9 > top of Msdn Tech,Visual Studio,Crystal Reports for Visual Studio...
# 6

Replace the single quote with double quote.

string= " This is Angel's Sample ".replace("'", "''")

SouravParida at 2007-9-9 > top of Msdn Tech,Visual Studio,Crystal Reports for Visual Studio...

Visual Studio

Site Classified