Hello,
I’m a newbie to the linq reporting engine.
I use xml files as data source. It might happen that some fields that are used in the doc template do not exist in the xml. It depends if that data exists in our backend data or not.
This is the xml-file:
<?xml version="1.0" standalone="yes"?>
<Data>
<Anzahl>2</Anzahl>
<NV>
<Anrede>Hello</Anrede>
<Anschrift1>Herrn</Anschrift1>
<Anschrift2>Name of customer</Anschrift2>
<Anschrift5>Street</Anschrift5>
<Anschrift6>Town</Anschrift6>
</NV>
</Data>
That’s how I try to handle the conditionally available field NV.Anschrift3 in the doc template:
<<[NV.Anschrift1]>>
<<[NV.Anschrift2]>>
<<if[NV.Anschrift3!=null]>><<[NV.Anschrift3]>><</if>>
<<if[NV.Anschrift4!=null]>><<[NV.Anschrift4]>><</if>>
That’s my test code:
[Test]
public void TestConditional()
{
XmlDataSource source = new XmlDataSource(MyDir + "Mail merge data - ConditionalData.xml");
Document doc = new Document(MyDir + "Reporting engine template - TestConditionalData.docx");
ReportingEngine engine = new ReportingEngine();
engine.BuildReport(doc, source);
doc.Save(ArtifactsDir + "ReportingEngine.TestConditionalData.docx");
}
When calling engine.BuildReport it results in an exception:
System.InvalidOperationException: 'An error has been encountered at the end of expression ‘NV.Anschrift3!=n’. Can not get the value of member ‘Anschrift3’ on type ' ‘.’
As image:
I do not find any example how to handle fields that might be missing.
I tried with all forms of ? operator, but always run in a similar exception.
Would be great if anybody can give me hint how to solve that problem.