LINQ Reporting Engine - Any() and Contains() is not working

Hi Team.
SampleTemplate.docx (33.1 KB)

I am passing a Json string to the word document and have added some conditional checks within the document.
[FindingsAndRecommendations?.Any(x => x.ParentSection == “Portfolio Management”)] does not work if I send the string with space. The same works if passing only JSON, but JSON string as the input it fails.
Also, <<if [(ClientTypes?.Contains(“HedgeFunds”) == true) || (ClientTypes?.Contains(“PrivateMarkets”) == true)]>>
is failing even if the JSON contains the string value mentioned. In this case <<if [ClientTypes?.Any(x=> x ==“HedgeFunds”)]>> is also failing.
Below is the JSON string.
"{\"ClientTypes\":[\"HedgeFunds\",\"RegisteredInvestmentCompanies\",\"WealthManager\"],\"FindingsAndRecommendations\":[{\"parentSection\":\"PortfolioManagement\"},{\"parentSection\":\"Trading\"}]}"

Have uploaded the sample document for the same.

Please let me know if any more details are required.

@mamatha.n

Could you please also provide sample code reproducing the issue?

@ivan.lyagin
Below is the sample code,

string json = //above json converted to string
Document doc = new Document(//document);
MemoryStream j = new MemoryStream(Encoding.UTF8.GetBytes(json ?? ""));
options.AlwaysGenerateRootObject = true;
JsonDataSource dataSource = new JsonDataSource(j, options);
ReportingEngine engine = new ReportingEngine();
engine.Options |= ReportBuildOptions.AllowMissingMembers;
engine.Options |= ReportBuildOptions.RemoveEmptyParagraphs;
engine.BuildReport(doc, dataSource);
doc.Save();

Also from the above question [FindingsAndRecommendations?.Any(x => x.ParentSection == “Portfolio Management”)] this is working fine.
still facing issue with this, " Also, <<if [(ClientTypes?.Contains(“HedgeFunds”) == true) || (ClientTypes?.Contains(“PrivateMarkets”) == true)]>>
is failing even if the JSON contains the string value mentioned. In this case <<if [ClientTypes?.Any(x=> x ==“HedgeFunds”)]>> is also failing."

@mamatha.n

This is because there is a mismatch in JSON data and template condition: JSON data contains “PortfolioManagement” (without a whitespace) whereas “Portfolio Management” (with a whitespace) is used within the template. After adding a whitespace to the corresponding JSON value, the issue is gone.

This is due to special treatment of JSON arrays containing simple values by LINQ Reporting Engine. Here is a relevant quote from Accessing JSON Data:

Note – To reference a JSON object property that is an array of simple-type values, the name of the property (for example, “Child”) should be used in a template document, whereas the same name with the “_Text” suffix (for example, “Child_Text”) should be used to reference the value of an item of this array.

Please check SampleTemplate_Modified.docx (30.4 KB) illustrating this.

@ivan.lyagin,
Thanks for the update on this. The Any() with “Child_Text” works perfectly fine.

Wanted to know how to we check for Contain(), seems like in the document you have shared, Contains() have been removed/changed to Any(). How do I check Contains() for a array of simple-type values.

@mamatha.n

Internally, an array of simple-type values is represented as an array of objects, so every item becomes an object (that is why, you can access an item value using the “…_Text” property of this object). As per Enumeration Extension Methods in C#, Contains’ parameter is a value to be searched for, so it should be this object representing an item rather than a string. That is why, Contains does not work for this case and was replaced with Any.