cancel
Showing results for 
Search instead for 
Did you mean: 

Change subreport properties using .NET SDK

HML
Explorer
0 Kudos

Hello,
I'm using Crystal Reports SDK for semi-automated report customizing and I am currently facing a very strange issue:

As soon as I change a property of a subreport (e.g. background color, position) Crystal Reports throws an InternalException "Invalid field name" for some reports when calling ReportDocument.Save or ReportDocument.Refresh. Even if I start printing or preview after the change, I get the same error.

I created two almost identical reports (let's say testreport_01 and testreport_02) for testing. Both reports contain a subreport and a formula field that is linked to a parameter in the subreport.

The only difference: The parameter in testreport_01 was created manually before linking and in testreport_02 the parameter field was created automatically when the subreport link was created.

HML_0-1714718483039.png

HML_1-1714718500689.png

testreport_01.rpt passes the following test, testreport_02.rpt turns red.

 

using CrystalDecisions.CrystalReports.Engine;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Drawing;

namespace ChangeSubreportTestProject
{
    [TestClass]
    public class ChangeSubreportTests
    {
        [TestMethod]
        [DataRow("./testdata/testreport_01.rpt")]
        [DataRow("./testdata/testreport_02.rpt")]
        public void TestChangeBackgroudColor(string filename)
        {
            var reportDocument = new ReportDocument();
            reportDocument.Load(filename);

            var reportObjects = reportDocument.ReportDefinition.ReportObjects;

            foreach (ReportObject reportObject in reportObjects)
            {
                if (reportObject is SubreportObject)
                    reportObject.Border.BackgroundColor = Color.Red;
            }

            reportDocument.SaveAs(filename + ".customized.rpt");

            reportDocument.Close();
            reportDocument.Dispose();
        }
    }
}

 

What I also found out so far:
1. The problem does not occur if the check "Select data in subreport based on field" is set when linking.
2. If I catch the exception when saving and call ReportDocument.SaveAs again, the report is saved, but the parameter field has disappeared.

Is there any way to avoid this problem without manually replacing the parameter fields in the affected reports?
Or if not, how can I at least identify the affected parameters?

I'm using the latest runtime version 13.0.34 resp. 13.0.35

Accepted Solutions (0)

Answers (0)