1909599 - How to set the formula syntax used for a report using the .NET Report Document SDK

SAP Knowledge Base Article - Public

1909599 - How to set the formula syntax used for a report using the .NET Report Document SDK

Symptom

Legacy craxdrt RDC code is being converted to .NET ReportDocument object SDK but there does not seem to be an equivalent of the formula syntax property, for example:

CRAXDRT.Report.FormulaSyntax =crBasicSyntaxFormula

Environment

  • Crystal Reports 2011
  • Visual Studio 2010
  • Crystal Reports for Visual Studio 2010

Cause

There is no equivalent functionality to do this at the report level. This can be done at the formula level using the RAS SDK.

Resolution

This function demonstrates how to change the text and syntax of a particular formula field by name:

private void ChangeFormulaText(ISCDReportClientDocument reportClientDoc, string formulaName, string formulaText, CrystalDecisions.ReportAppServer.DataDefModel.CrFormulaSyntaxEnum formulaSyntax)
        {
            CrystalDecisions.ReportAppServer.DataDefModel.FormulaField oldFormulaField;
            int oldFormulaFieldIndex;

            oldFormulaFieldIndex = reportClientDoc.DataDefinition.FormulaFields.Find(formulaName, CrystalDecisions.ReportAppServer.DataDefModel.CrFieldDisplayNameTypeEnum.crFieldDisplayNameName, CrystalDecisions.ReportAppServer.DataDefModel.CeLocale.ceLocaleUserDefault);
            oldFormulaField = (CrystalDecisions.ReportAppServer.DataDefModel.FormulaField)reportClientDoc.DataDefinition.FormulaFields[oldFormulaFieldIndex].Clone(true);
            oldFormulaField.Text = formulaText;

            oldFormulaField.Syntax = formulaSyntax;

            reportClientDoc.DataDefController.FormulaFieldController.Modify((CrystalDecisions.ReportAppServer.DataDefModel.FormulaField)reportClientDoc.DataDefinition.FormulaFields[oldFormulaFieldIndex], oldFormulaField);
        }

And this can be called from the ReportDocument object like this:

ReportDocument rptDoc = new ReportDocument ();
rptDoc.Load ("c:/test/test.rpt");

ISCDReportClientDocument rptClientDoc = rptDoc.ReportClientDocument;
ChangeFormulaText (rptClientDoc, "test", "formula = 42", CrystalDecisions.ReportAppServer.DataDefModel.CrFormulaSyntaxEnum.crFormulaSyntaxBasic);
crystalReportViewer1.ReportSource = rptDoc;

Keywords

CR2010 2010 CR4VS2010 CR4VS VS2010 NET2010 Crystal Reports for .NET Framework 4.0 crforvs 13 CR2008 2008 12 , KBA , BI-DEV-NET-SDK , .NET SDK / COM SDK , How To

Product

Crystal Reports 2008 V1 ; SAP Crystal Reports XI R2 ; SAP Crystal Reports, developer version for Microsoft Visual Studio