<<foreach[ent in Entities]>>
<<var[DateTime date1 = ent.StartDate]>>
<<var[DateTime date2 = ent.EndDate]>>
<<if[date1.ToString("MMyyyy") == date2.ToString("MMyyyy")]>>
Dates are in the same month
<</if>>
<</foreach>>
@airbags Please try modifying your template like this:
<<foreach[ent in Entities]>>
<<var[date1 = ent.StartDate]>>
<<var[date2 = ent.EndDate]>>
<<if[date1.ToString("MMyyyy") == date2.ToString("MMyyyy")]>>
Dates are in the same month
<</if>>
<</foreach>>
And set ReportBuildOptions.AllowMissingMembers option. For example see the following code:
JsonDataSource data = new JsonDataSource(@"C:\Temp\data2.json");
Document doc = new Document(@"C:\Temp\in.docx");
ReportingEngine engine = new ReportingEngine();
engine.Options = ReportBuildOptions.AllowMissingMembers | ReportBuildOptions.RemoveEmptyParagraphs;
engine.BuildReport(doc, data, "Entities");
doc.Save(@"C:\Temp\out.docx");
@alexey.noskov thanks for the advice. Coupled with the advice you gave from a previous thread, I’ve come up with the following syntax that gets the start and end dates in the format our client requires for their reports and doesn’t error when an empty array is entered.
No need for the AllowMissingMembers as I believe this was an issue with the linq reporting engine trying to evaluate variables in the foreach loop and not being able to cast to not-nullable DateTime variable.
I’ve opted to cast in the conditions rather than at the variable declaration.
@airbags It is perfect that you managed to achieve what is required. optionaly insted of casting, you can use date1.Value.ToString("ddMMyyyy") syntax instead of casting nullable DateTime to DateTime. Please see the following updated syntax: