cancel
Showing results for 
Search instead for 
Did you mean: 

How to set Crystal Report special fields 'Print Date' value in .net

Former Member
0 Kudos

I have few crystal reports using the yeartodate, monthtodate, printdate in the formula fields. The user can use 'Set print date and time...' function under Designer report menu to generate the report. However, now we will use .net report viewer control to render reports through our .net window application. Without modifying the existing reports, is there a way to change this print date and time through .net code? If we need to modify the report, is there an easy way to do that?

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hello,

Not sure which version you are actually using but search using the Object browser on this function:

PrintDate

Member of CrystalDecisions.Shared.SpecialVarType

If it doesn't exist then you'll have to upgrade to the full Crystal Report Developer version and then you also have the option to use RAS also to modify reports at runtime:

crSpecialFieldTypePrintDate

Member of CrystalDecisions.ReportAppServer.DataDefModel.CrSpecialFieldTypeEnum

Thank you

Don

Former Member
0 Kudos

Don,

Thanks for the quick reply. I have VS 2008, and Crystal report designer 2008. I can see the CrystalDecisions.Shared.SpecialVarType.PrintDate in my .net development environment.

Now goes to the next step, at what point can I set this value for the report? I have a code snip in here that I am using to launch the report viewer:

ReportDocument client = new ReportDocument();

client.Load(reportName);

ConnectionInfo connectionInfo = new ConnectionInfo();

connectionInfo.ServerName = connStr;

connectionInfo.DatabaseName = "xxx";

connectionInfo.UserID = "xxx";

connectionInfo.Password = "xxx";

SetDBLogonForReport(connectionInfo, client);

SetDBLogonForSubreports(connectionInfo, client);

crystalReportViewer.ReportSource = client;

crystalReportViewer.RefreshReport();

0 Kudos

After you set the log on info and before you view the report. Check the Developers help file on using the API.

Thank you

Don

Former Member
0 Kudos

Don,

I went to https://www.sdn.sap.com/irj/boc/businessobjects-sdklibrary to download developer help or API file under .net SDK. The downloaded help file, named crsdk_net_apiRef_12_en.chm, has the correct content list on the left side, but the right side content displays "The page cannot be displayed" message. What is the problem?

Thanks,

0 Kudos

Could be your pop up blocker is stopping it from updating or some browser settings. Works for using IE 6 and 7.

Former Member
0 Kudos

Don,

I want to email you the error with screen capture image. Do you have an email address that I can attache the image file? I am using IE 6.0.2900.5512.xpsp_sp3_gdr.080814-1236.

Thanks,

0 Kudos

No, sorry you can't attach files to Forums and we don't give out our e-mail adresses. Try Refreshing the page and clearing your cache.

0 Kudos

Here's the direct links:

Crystal Reports .NET SDK

http://help.sap.com/businessobject/product_guides/boexir31/en/crsdk_net_apiRef_12_en.chm

Report Application Server .NET SDK

http://help.sap.com/businessobject/product_guides/boexir31/en/rassdk_net_apiRef_12_en.chm

I don't have specific code to add this field but here is code to add a chart, same process just use the Print Date references:

CrystalDecisions.ReportAppServer.ReportDefModel.ChartObject boChartObject;

CrystalDecisions.ReportAppServer.ReportDefModel.ChartStyle boChartStyle;

CrystalDecisions.ReportAppServer.ReportDefModel.Section boSection;

CrystalDecisions.ReportAppServer.DataDefModel.Fields boFields;

CrystalDecisions.ReportAppServer.DataDefModel.Field boField;

CrystalDecisions.ReportAppServer.DataDefModel.SummaryField boSummaryField;

int boFieldIndex;

{

rpt.Load("D:
SimpleRCAPIReport.rpt");

rptClientDoc = rpt.ReportClientDocument;

boFields = rptClientDoc.DatabaseController.Database.Tables[0].DataFields;

//Create a chart

boChartObject = new CrystalDecisions.ReportAppServer.ReportDefModel.ChartObject();

//create a bar chart style

boChartStyle = new CrystalDecisions.ReportAppServer.ReportDefModel.ChartStyle();

boChartStyle.Type = CrystalDecisions.ReportAppServer.ReportDefModel.CrChartStyleTypeEnum.crChartStyleTypeBar;

//set the chart style to bar chart

boChartObject.ChartStyle = boChartStyle;

//set the chart type to advanced chart

boChartObject.ChartDefinition.ChartType = CrystalDecisions.ReportAppServer.ReportDefModel.CrChartTypeEnum.crChartTypeDetail;

//set Customer Name field as condition field

//get the Customer Name field

boFieldIndex = boFields.Find("Customer Name",

CrystalDecisions.ReportAppServer.DataDefModel.CrFieldDisplayNameTypeEnum.crFieldDisplayNameName,

CrystalDecisions.ReportAppServer.DataDefModel.CeLocale.ceLocaleUserDefault);

boField = (CrystalDecisions.ReportAppServer.DataDefModel.Field)boFields[boFieldIndex];

boChartObject.ChartDefinition.ConditionFields.Add(boField);

boField = null;

//set Last Year's Sales as data field

//get {Customer.Last Year's Sales field}

boFieldIndex = boFields.Find("Last Year's Sales",

CrystalDecisions.ReportAppServer.DataDefModel.CrFieldDisplayNameTypeEnum.crFieldDisplayNameName,

CrystalDecisions.ReportAppServer.DataDefModel.CeLocale.ceLocaleUserDefault);

boField = (CrystalDecisions.ReportAppServer.DataDefModel.Field)boFields[boFieldIndex];

//create a Sum({Customer.Last Year's Sales})

boSummaryField = new CrystalDecisions.ReportAppServer.DataDefModel.SummaryField();

boSummaryField.SummarizedField = boField;

boSummaryField.Operation = CrystalDecisions.ReportAppServer.DataDefModel.CrSummaryOperationEnum.crSummaryOperationSum;

boSummaryField.Type = boField.Type;

//add summary field to report client document

rptClientDoc.DataDefController.SummaryFieldController.Add(-1, boSummaryField);

boChartObject.ChartDefinition.DataFields.Add(boSummaryField);

//set chart coordinates and dimensions (0, 0), width = 7 inches, height = 5 inches

boChartObject.Left = 0;

boChartObject.Top = 0;

boChartObject.Width = 7 * 1440; // 1 inch = 1440 twips

boChartObject.Height = 5 * 1440;

//get report header section

boSection = rptClientDoc.ReportDefinition.ReportHeaderArea.Sections[0];

//set chart report area to report header

boChartObject.ChartReportArea = CrystalDecisions.ReportAppServer.ReportDefModel.CrAreaSectionKindEnum.crAreaSectionKindReportHeader;

//add chart in the report header

rptClientDoc.ReportDefController.ReportObjectController.Add(boChartObject, boSection, -1);

MessageBox.Show("Chart Added", "RAS", MessageBoxButtons.OK, MessageBoxIcon.Information);

}

Thanks again

Don

former_member208657
Active Contributor
0 Kudos

You'll want to look at note 1271550 here https://www.sdn.sap.com/irj/boc/businessobjects-notes.

Just to clarify, this note above is why you are getting the error trying to get to the SDK help file:

Don,

I went to https://www.sdn.sap.com/irj/boc/businessobjects-sdklibrary to download developer help or API file under .net SDK. The downloaded help file, named crsdk_net_apiRef_12_en.chm, has the correct content list on the left side, but the right side content displays "The page cannot be displayed" message. What is the problem?

Thanks,

Edited by: Don Williams on Jan 26, 2009 12:58 PM

Answers (1)

Answers (1)

Former Member
0 Kudos

Here is my original question: How to duplicate the 'Set print date and time ...' function in the Crystal report designer into the .net code to do the same thing while viewing the existing report in the .net reportviewer. The existing reports are using the yeartodate, monthtodate, printdate in the formula fields, and might not be placed on the report itself (just use the date value to perform filtering on the data). The solution provided in here points me to the reportDocument.ReportDefinition.ReportObjects, which will only help if the printDate is placed on the report, not just used in the formula. Without modifying the existing report, I want to know if it is possible in .net code to have the same functional capability that provided in the Crystal Report desginer. Thanks

0 Kudos

Hello,

Sorry but it's really not clear what you are asking?

The special fields 'Print Date' simply adds that field to the report and it gets the date from the local computers system date, it does not add any filtering so it's really not clear what you want to do... The Print date gets it's date from the local PC and drops the value into the report in the field holder, you can't change the value. Or use the Special field "Data Date" which adds the date when the report was generated, the Print Date will change everytime you open the report and view it.

So it may be we assumed you want to add this because as a report designer you would know using that field gets updated each time the report is viewed. Or it may be that you noticed it does get updated and you want to change it back in which case use the Data Date field in the report.

Other option is to add a text field and change the text with the date you want printed.

You can also make a copy of the original report and do with it what ever you want and simply close it without saving.

Thank you

Don

Former Member
0 Kudos

Hi Don,

I will make it clear this time. I have a report with three formulas. One of the formulas on the report works like this:

if ({table.sales_year_month} in YeartoDate) Then

{table.net_sales}

else

0

In the report, sales_year_month and net_sales fields are in the detail section. When users run the report in the designer, they can use the u201CSet Print Date and Timeu2026u201D function to change the YeartoDate value used in the report to filter out the data they wanted. For example, users can generate report for the previous year or previous month by using this feature.

Now the question comes to what can we do to achieve the same thing in .net without modifying this report.

Thanks,

0 Kudos

It's still not completely clear how you are doing all this. But what you can do is simply use the RecordSelectionFormula to add the date filtering. Create your own date prompt to add filtering and apply it to the Selection formula.

It appears you may be using the .NET IDE Report Designer or possible craxddrt.dll? Just a warning you can't distribute it for end users depending on the version you are using. CR 2008 no longer is licensed to use it.

You make any changes from the original and you are modifying the report in code only, like I said as long as you don't save the report your changes won't be saved.

Try getting the reocrd selection formula and see if that helps you.

I think we need to get back to the basics:

What version of Crystal Reports are you using?

What version of .NET are you using?

What development language are you using?

What report engine are you using, RDC or .NET CR Engine or RAS assemblies?

Is this a Windows or WEB application.

Can you add code to show what you are doing and where you want to add the functionality?

Former Member
0 Kudos

Don,

The solution you suggested is what we thought we need to do, but I just want to see if there is an easy way to solve this problem.

Get back to your question: We are not using .net IDE for report designer, we just use the report viewer to render the report. The report is designed using CR2008 designer. The application is a Windows app, not a web app, .net 2.0 version is used, and CrystalDecisions.CrystalReports.Engine is used.

Thanks, I will mark this question as answered.

former_member208657
Active Contributor
0 Kudos

I had a good look through the CR and RAS .NET SDK's using .NET Reflector and didn't find any way to set the print date and time. It looks like this is locked down to the designer only.

Too bad. It would be a nice feature to have in the SDK.