1284635 - How can I add a report formula using the Crystal Reports .NET inproc RAS SDK?

SAP Knowledge Base Article - Public

1284635 - How can I add a report formula using the Crystal Reports .NET inproc RAS SDK?

Symptom

How can I add a report formula using the Crystal Reports .NET inproc RAS SDK

Reproducing the Issue

.NET Visual Studio 2005
C#

Resolution

How can I add a report formula using the Crystal Reports .NET inproc RAS SDK

        using CrystalDecisions.CrystalReports.Engine;
        using CrystalDecisions.ReportAppServer.ClientDoc;
        using CrystalDecisions.ReportAppServer.DataDefModel;

 
         ReportDocument                       m_boReportDocument;
         ISCDReportClientDocument    m_boReportClientDocument;
         FormulaField                              m_boFormula;

         //Create a new ReportDocument
         m_boReportDocument = new ReportDocument();

         // load the RPT file 
         m_boReportDocument.Load("..\\..\\AddFormula.rpt");

         //Access the ReportClientDocument in the ReportDocument (EROM bridge)
         m_boReportClientDocument = m_boReportDocument.ReportClientDocument;
  
         //Create a new Formula Object 
         m_boFormula = new CrystalDecisions.ReportAppServer.DataDefModel.FormulaField() ;
 
          //Set it's properties
          m_boFormula.Text = "//Please enter your Formula here";
          m_boFormulaField.Text = "//{Customer.Contact First Name} + ' ' + {Customer.Contact Last Name}";
          m_boFormulaField.Name = "//CustomerName";
          m_boFormulaField.Syntax = CrystalDecisions.ReportAppServer.DataDefModel.CrFormulaSyntaxEnum.crFormulaSyntaxCrystal;
          m_boFormulaField.Type = CrystalDecisions.ReportAppServer.DataDefModel.CrFieldValueTypeEnum.crFieldValueTypeStringField;
            
          //Add to the report
          m_boReportClientDocument.DataDefController.FormulaFieldController.Add(m_boFormula);
           
          // show in reportviewer
          crystalReportViewer1.ReportSource = m_boReportDocument;

Note:
Prior to the release of Crystal Reports XI R2 Service Pack 2, report modification was only possible using the RAS (Report Application Server) SDK with a RAS server or by using In-Process RAS with the purchase of additional licensing.
Using Crystal Reports  XI R2 Service Pack 2 and higher, you can now access the report modification APIs without any additional licensing by using the inprocess-RAS engine through the Crystal Reports .NET SDK. An example of accessing the RAS SDK through the Crystal Reports  .NET SDK is as follows:

See Also

Keywords

RAS, Modification, In-Process, .NET, Create, Add, Remove, Change, Modify, ReportClientDocument, inproc, FormulaField , 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