Skip to Content
1

FieldObject copying, with RAS, incomplete. Possible API error?

Oct 27, 2017 at 11:52 AM

127

avatar image
Former Member

Hi everyone,

I'm in process of programmatically copying many reports, cause my company has some issues with older ones.

If I'm duplicating a formulafield, for my new report, everything is copied correct, except the textinterpretation condition formula. Every other reportobject is copied completly! Why is, in the formulafield paragraph segment, a conditionformula missing? But all other conditionformulas, or settings in common, border or font are duplicated correctly.
I've looked around and i can even set the textinterpretation-property but not the textinterpretation condition formula.

Setting this condition by hand is no option cause one report has at least 20 to 30 formulafields.

I found a post from 2010 where someone had a similar problem. But 3 Versions prior. Is there a solution now with CR Version 13? When not, why is the process of duplication incomplete with a formulafield?

I'm copying like the procedure mentioned here:
https://answers.sap.com/questions/339342/where-can-i-set-the-textinterpretation-formula-of.html

I would appreciate any help.

Thanks
Jessica

In use:
- SAP Crystal Reports for Visual Studio 2017
- Crystal Reports Version: 13.0.21.2533
- I'm using the in proc RAS API

1z9az.png (10.0 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
Don Williams
Nov 15, 2017 at 05:01 PM
0

You really don't need to duplicate the report. Printing does work and I've spent a lot of time doing so and testing.

How about testing with my printer test app and see if that works for you?

Printing Crystal Reports in .NET

Forums is the bottom of the list of things to do. I don't have time right now to test this again.

Printing does work as well as selecting the colour option. You need to use PrintOutputController API

That I have tested and it does work.

Don

Share
10 |10000 characters needed characters left characters exceeded
Don Williams
Nov 06, 2017 at 02:41 PM
0

I had time to test this on friday. I have not been able to find a way to get the text so I pinged DEV for an example or how to and he was busy so possibly tomorrow....

Don

Update: We found some older Escalations and discovered it is not possible to get String condition formula, numbers do work.

R&D OK'd to create a case and get this Enhancement done. They will look into seeing if it's possible and add if they can.

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Thank you for testing and keep on answering.

"R&D OK'd to create a case and get this Enhancement done. They will look into seeing if it's possible and add if they can."
will you update again if you get an answer, please.

Jessica

0
Don Williams
Oct 27, 2017 at 06:09 PM
0

Hi Jessica,

Can you send the report? you need to find a FTP server, we don't have one.

See if this returns them?

{
btnReportObjects.Text = "";
flcnt = 0;
Errorcnt = 0;

foreach (CrystalDecisions.ReportAppServer.ReportDefModel.ReportObject reportObject in rptClientDoc.ReportDefController.ReportObjectController.GetAllReportObjects())
{
var reportSection = rptClientDoc.ReportDefController.ReportDefinition.FindSectionByName(reportObject.SectionName);
for (int index = 0; index < reportSection.Format.ConditionFormulas.Count; ++index)
{
var formula = reportSection.Format.ConditionFormulas[(CrystalDecisions.ReportAppServer.ReportDefModel.CrSectionAreaFormatConditionFormulaTypeEnum)index];
var NewFormula = reportSection.Format.ConditionFormulas[(CrystalDecisions.ReportAppServer.ReportDefModel.CrSectionAreaFormatConditionFormulaTypeEnum)index];

try
{
if (formula.Text != null)
{
textBox1 = "Condition Formula: " + formula.Text.ToString() + "\n";
textBox1 += "Section " + reportSection.Name + "\n";
btnReportObjects.Text += textBox1;
btnReportObjects.AppendText(" 'End' \n\n");
textBox1 = "";
++flcnt;
btnCount.Text = flcnt.ToString();
}
}
catch (Exception ex)
{
btnReportObjects.Text += "\nException: " + ex.ToString();
++Errorcnt;
btnErrorCount.Text = Errorcnt.ToString();
}

Don

Show 5 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi Don,

I can't send the report, where our problem occures.
But I can replicate my problem. You just need to create a report with a formulafield and navigate to the paragraph section, set the conditionformula for textinterpretation (and all other conditionformulas for comparing reasons) and save the report.

Now copy this report with RAS and only the textinterpretation conditionformula is missing.
Why?

--

I did alter your code, cause I don't understand why you work with buttons ...

var reportSection = rptRcd.ReportDefController.ReportDefinition.FindSectionByName( "PageHeaderSection1" );
foreach ( ReportObject item in reportSection.ReportObjects )
 {
 for ( int i = 0; i < reportSection.Format.ConditionFormulas.Count; i++ )
  {
  var formula = reportSection.Format.ConditionFormulas[(CrSectionAreaFormatConditionFormulaTypeEnum)i];
  try
   {
    if ( formula.Text != null )
    {
  Console.WriteLine(item.Name + " "+ formula.Text );
    }
   }
  catch ( Exception ex )
  {
  Console.WriteLine( ex.ToString() );
  throw;
  }
 }
}

When I try this code I just get the section conditionformula (like the enum suggests).

While I did take a look around there are enums for:

  • Common = CrCommonFieldFormatConditionFormulaTypeEnum
  • Border = CrBorderConditionFormulaTypeEnum
  • Font = CrFontColorConditionFormulaTypeEnum

Which enum belongs to the paragraph section or rather textinterpretation?

We did had holidays, thats why I answer this late, sorry.

Thanks

Jessica

0

Hi Jessica,

Sorry, my code was just to get the info. What you need to do is use the .Clone() function to completely copy the object, make changes to it and then add/replace the object.

When making any deep changes you need to clone the object. Note, some objects are in a read only state so they cannot be altered in code.

Here's the updated code:

if (reportObject.Name == "Text18")
{
// check the formula by adding it to the report to verify the syntax
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 = @"if {Customer.Country} = 'Canada' then Color (150,230,150) else Color (10,19,200)"; //@"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)
{
//then add the conditional formula if it's OK
string newFormulaText = Formula.Text; // "'It Worked' = 'It Worked'";
// Clone a Section Format and use ReportSectionController.SetPropety to modify the ConditionFormulas
CrystalDecisions.ReportAppServer.ReportDefModel.SectionFormat newFormat = reportSection.Format.Clone(true);
newFormat.ConditionFormulas[(CrystalDecisions.ReportAppServer.ReportDefModel.CrSectionAreaFormatConditionFormulaTypeEnum)index].Text = newFormulaText;
rptClientDoc.ReportDefController.ReportSectionController.SetProperty(reportSection, CrReportSectionPropertyEnum.crReportSectionPropertyFormat, newFormat);
}
else
btnReportObjects.Text += "There are errors in the formula: " + FormulaMessage.ToString() + "\n";
}

See if that works for you

Don

0
Former Member

Hi Don,

I am a little bit frustrated. May I don’t understand how your code example can help me solve my problem, or you don‘t understand what my problem really is. My wording is a little bit off ... I did mean the tabs/ index cards of the format editor/expert with my description of sections. Not report sections.

For example I added screenshots of my problem. If I open the copied report with the CR-Designer you can see the textinterpretation conditionformula is not set, but all other conditionformulas in the corresponding tabs of this databasefield.

Problem:

Even if I try to use the .Clone(true) or the .CopyTo(obj, true) function I don’t get these settings.
You said: “Note, some objects are in a read only state so they cannot be altered in code.” Do this mean the textinterpretation conditionformula is not get-/setable? Do I really have to go the old way with the not supported RCD api? I know this textinterpretation formula was accessible there.

--

Your code gives me the ability to alter condition formulas from sections, or of other objects if I change the CrEnum.

I already can copy a section with all their specific settings. My problems are with the textinterpretation conditionformula of formulafields or databasefields, in paragraph tab of the format-editor. All other conditionformulas of these objects I can get and set, but not the textinterpretation formula.

Thanks

Jessica

gbws4.png (18.1 kB)
l8vmj.png (49.6 kB)
0

Hi Jessica,

So now my question is is why are you duplicating the report by updating all of the various objects?

If you simply need to get the reports up to a current version just use the SaveAs() in code and it will update the version.

private void btnSaveReportAs_Click(object sender, System.EventArgs e)
{
    saveFileDialog.Filter = "Crystal Reports (*.rpt)|*.rpt";
    if (DialogResult.OK == saveFileDialog.ShowDialog())
    {

        object saveFolder = System.IO.Path.GetDirectoryName(saveFileDialog.FileName);
        string saveFileName = System.IO.Path.GetFileName(saveFileDialog.FileName);

        if (!IsRpt)
        {
            try
            {
            rptClientDoc.SaveAs(saveFileName, ref saveFolder,
                (int)CdReportClientDocumentSaveAsOptionsEnum.cdReportClientDocumentSaveAsOverwriteExisting);
            }
            catch (Exception ex)
            {
                btnSQLStatement.Text = "ERROR: " + ex.Message;
                return;
            }
        }
        else
        {
            try
            {
                rpt.SaveAs(saveFolder + "\\" + saveFileName, true);
            }
            catch (Exception ex)
            {
                btnSQLStatement.Text = "ERROR: " + ex.Message;
                // SetLogonInfo_Click();
                //return;
            }
        }
    }
}

Thanks again

Don

0
Former Member

Hi Don,

our original problem lies with printing reports.
In our application we are still using the RCD api. Some customers encountered a strange behaviour with reports, where they could change any colour options but they weren’t printed out.

For example, a customer wants an invoice to be printed in black and white, since his printer colours are nearly empty. He checks the no colour print option, but the printer prints the report still in colour. We did check where this behaviour could come from, it seems like the report is saving some printing information even if we check the “no printer” option in the report (like from the default printer). The issue doesn’t occur if we print with the CR Designer, but not all of our customers want to open them.

Our problem is similar to this post. We do not have the workers do integrate the new .Net api so we try with fixing issues. May with the tool I am creating we gain enough knowledge to solve our problem or to upgrade to the new api … but that’s far away.

For the last past months I researched the .Net api. With the report printoptions, or paperorientationoptions I didn’t find a solution. Like the information I was searching for is not accessible. However, with creating a new report from scratch I’m able to solve our issue.

Pls answer my original question, you would help me a great deal.

Thanks again.

Jessica

0