SAP Knowledge Base Article - Public

3045716 - how to Rename a formula fields with Crystal reports for Visual Studio .NET SDK

Symptom

 I need to rename a formula field by code. Is there a way to do this without remove and add so that references to the formula are changed too?

Environment

Crystal Reports Developer, for Visual Studio

Reproducing the Issue

here's the code I tried:

                            FormulaField oOldFormulaField = resultField;
                            FormulaField oFormulaField = new FormulaField();
                            //resultField.CopyTo(oFormulaField, false);
                            oFormulaField = (FormulaField)resultField.Clone(true);
                            oFormulaField.Text = @"'Don " + oFormulaField.Text.ToString() + "'";
                            oFormulaField.Name = @"Don";
                            rptClientDoc.DataDefController.FormulaFieldController.Modify(oOldFormulaField, oFormulaField); 
 
Problem is this generates an error:
System.Runtime.InteropServices.COMException
  HResult=0x8004200A
  Message=The Name property of the old and new formula fields must be the same.
  Source=CrystalDecisions.ReportAppServer.Controllers
  StackTrace:
   at CrystalDecisions.ReportAppServer.Controllers.FormulaFieldControllerClass.Modify(Object OldFormulaField, FormulaField NewFormulaField)
   at Unmanaged_RAS10_CSharp_Printers.frmMain.ReportObjectComboBox1_SelectedIndexChanged(Object sender, EventArgs e) in D:\CPP Net 2019\RAS2010_CsharpPrinter\Form1.cs:line 10513
   at System.Windows.Forms.ComboBox.OnSelectedIndexChanged(EventArgs e)
   at System.Windows.Forms.ComboBox.WmReflectCommand(Message& m)
   at System.Windows.Forms.ComboBox.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
 

Resolution

The issue is in CR Designer it has routines that scans all other collections and renames any reference to the formula name.

The .NET SDK does not have this ability and at this time there are no plans to add it.

Solution is to use CR Designer to change the names so it cna propagate the change throughout the report.

Keywords

crforvs, change formula name, .net, The Name property of the old and new formula fields must be the same. , KBA , BI-DEV-NET , BI Software Development Kits (SDKs) - .NET or Other , Problem

Product

SAP Crystal Reports, developer version for Microsoft Visual Studio