SAP Knowledge Base Article - Public

1704566 - How to change formula text at runtime using Crystal Reports Application Server .NET SDK

Symptom

When attempting to change the text of a formula field using Crystal Reports Application Server .NET SDK an exception is thrown.

Environment

Crystal Reports for Visual Studio 2010

Resolution

Sample code:

We could avoid this issue by adding reportclientdocument.verifydatabase() between FormulaFieldcontroller.modify() and reportobjectcontroller.modify() as below, then there is no error:
//set the formula text
CrystalDecisions.ReportAppServer.DataDefModel.FormulaField newFormulaField = (CrystalDecisions.ReportAppServer.DataDefModel.FormulaField)formulaField.Clone(true);
newFormulaField.Text = "Abs (789.00)";
rcd.DataDefController.FormulaFieldController.Modify( formulaField, newFormulaField);
// Add this line to tell RAS to sync the object collections
rcd.VerifyDatabase();
//change the properties on the new object
int hexcol = (int)newKnownColor;
int decVal = int.Parse(hexcol.ToString(), System.Globalization.NumberStyles.HexNumber);
CrystalDecisions.ReportAppServer.ReportDefModel.FieldObject formulaFieldObj;
newFormulaObj = (CrystalDecisions.ReportAppServer.ReportDefModel.FieldObject)formulaFieldObj.Clone(true);
newFormulaObj.FontColor.Font.Name = newFont.ToString();
newFormulaObj.FontColor.Font.Size = Convert.ToDecimal(newSize);
newFormulaObj.FontColor.Color = (uint)c.ToKnownColor(); 
rcd.ReportDefController.ReportObjectController.Modify(formulaFieldObj, newFormulaObj);
 
This issue has been resolved in Service Pack 3 for Crystal Reports for Visual Studio 2010

Keywords

Formula text, Crystal Reports for Visual Studio 2010, RAS , KBA , htkba , bisdk , BI-DEV-NET-SDK , .NET SDK / COM SDK , Problem

Product

SAP Crystal Reports, developer version for Microsoft Visual Studio