cancel
Showing results for 
Search instead for 
Did you mean: 

How do I edit formulas at once

Former Member
0 Kudos

So I find this very frustrating and have not found a solution ( I'm hoping there is one to make my life easier and more efficient ); i am trying to edit formulas and am having to do it one by one.  I have about 50 formulas or more, that are based upon columns in a stored procedure, and i need to change them to another stored procedure that has exact same columns.  However, the find and replace will not work on formulas just on text.

For example:

Current

  If (procA.needscellphone) = 1 then true else false

Need

   If (procB.needscellphone) = 1 then true else false

Yes both stored procedures have been added to the report

Is there anyway to change all these formulas at once?  Having to manually edit them one by one is tedious and seems to be quite archaic for a program like Crystal.  I hope someone has a way for me to do this in such a way that will significantly reduce my time.

thank you.

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hi Doug,

Use RAS to get the formula collection and the .Clone to copy it, make the change to the text and then use the .Modify to apply the change.

Something like this:

btnReportObjects.Text = "";

int flcnt = 0;

#region do not delete

////do not delete - this works

////rptClientDoc.DataDefController.FormulaFieldController.Remove(resultField);

//CrystalDecisions.ReportAppServer.ObjectFactory.ObjectFactory objFactory = new CrystalDecisions.ReportAppServer.ObjectFactory.ObjectFactory();

//CrystalDecisions.ReportAppServer.DataDefModel.FormulaField Formula = (CrystalDecisions.ReportAppServer.DataDefModel.FormulaField)objFactory.CreateObject("CrystalReports.FormulaField");

//Formula.Type = CrystalDecisions.ReportAppServer.DataDefModel.CrFieldValueTypeEnum.crFieldValueTypeStringField;

//Formula.Syntax = CrystalDecisions.ReportAppServer.DataDefModel.CrFormulaSyntaxEnum.crFormulaSyntaxCrystal;

//Formula.Text = @"whilereadingrecords; ""A"""; // "hello Ludek = 1"; // resultField.Text; // "n=3"; {Customer.Customer Credit ID} + 1 @"whilereadingrecords; ""A"""

//Formula.Name = "TestDon"; // "TestDon"; //  resultField.Name; //"testformula";

//String FormulaMessage = rptClientDoc.DataDefController.FormulaFieldController.Check(Formula);

//if (FormulaMessage == null)

//    rptClientDoc.DataDefController.FormulaFieldController.Add(Formula);

//else

//    btnReportObjects.Text += "There are errors in the formula: " + FormulaMessage.ToString() + "\n";

////do not delete - this works

#endregion do not delete

//rptClientDoc.SaveAs("don2.rpt", @"D:\Atest\CrystalTest_3501213_2013", 0);

btnCount.Text = rptClientDoc.DataDefController.DataDefinition.FormulaFields.Count.ToString();

foreach (FormulaField resultField in rptClientDoc.DataDefController.DataDefinition.FormulaFields)

{

    textBox1 = resultField.LongName.ToString();

    btnReportObjects.Text += textBox1;

    btnReportObjects.AppendText(" : Used: " + resultField.UseCount.ToString() + " times'End' \n");

    ++flcnt;

    btnCount.Text = flcnt.ToString();

    String FormulaMessage = rptClientDoc.DataDefController.FormulaFieldController.Check(resultField);

    if (FormulaMessage != null)

    {

        btnReportObjects.Text += FormulaMessage.ToString() + "\n";

    }

}

Don

Former Member
0 Kudos

Hmm interesting.   Thank you for the detailed response Don. For whatever reason, I had not considered attempting to do this in code.  I had been trying to do it in the visual designer and just could not find a way.  I will give it a shot in code.

thank you

0 Kudos

Ah, interesting also.... I assumed you would want to do this in code because I have never heard of someone asking to update all formula at once.

Possibly using a variable for the SP name may work... Still need to update the formula but at least next time it's only one place.

Don

ido_millet
Active Contributor

Answers (0)