
I'm building a custom application that generates and stores a layout template using the DocuTemplate apis. This process seems to work fine. I'm able to create and store a template for an excel document. The issue I'm having is on spreadsheet generation. The columns I've defined in the template appear fine but I'm not getting any entity data.
Below is the prototype code I'm using to generate the excel file. What's not clear to me is when/where the data entity is invoked to extract the data. I assume it's during the DocuTemplateRender.renderToStream operation. I feel I may be missing a step or I'm using the wrong APIs. Any thoughts or guidance would be appreciated.
private boolean tryGenerateReport(CustomContract _contract)
{
boolean success = false;
DocuTemplate template = DocuTemplate::findTemplate(OfficeAppApplicationType::Excel, _contract.parmLayoutName() + filename);
if (template)
{
boolean initialFiltersAreValid = true;
container filterContainer;
DocuFileSaveResult saveResult = DocuFileSave::promptForSaveLocation(template.TemplateID, MyConstants::ExcelExtension, "layout", "journal");
Map filtersToApply = new Map(Types::String, Types::Class);
this.prepareForExport(_contract.parmLayoutName());
// Create header filters.
ExportToExcelFilterTreeBuilder filterBuilder = new ExportToExcelFilterTreeBuilder(tablestr(ReportHeaderEntity));
var filter = filterBuilder.and(
filterBuilder.areEqual(fieldStr(ReportHeaderEntity, Company), curExt()),
filterBuilder.areEqual(fieldStr(ReportHeaderEntity, Name), _contract.parmLayoutName()));
filtersToApply.insert(tablestr(ReportHeaderEntity), filter);
if (initialFiltersAreValid)
{
System.IO.MemoryStream templateStream = new System.IO.MemoryStream();;
try
{
DocuTemplateRender renderer = new DocuTemplateRender();
renderer.renderTemplateToStream(template, filtersToApply, templateStream);
templateStream.Seek(0, System.IO.SeekOrigin::Begin);
success = this.processExport(templateStream);
// Pass the workbook to the user.
DocuFileSave::processSaveResult(templateStream, saveResult);
}
finally
{
if (templateStream != null)
{
templateStream.Dispose();
}
}
}
}
return success;
}
private boolean processExport(System.IO.Stream _stream)
{
boolean success;
str upLoadResult = ExportToExcelStorageHelper::uploadExportStream(_stream, OfficeAppApplicationType::Excel);
return success;
}
hi
It looks like you are on the right track with using the DocuTemplateRender class to generate the report. According to your code, you are passing a map of filters to apply to the renderTemplateToStream method. This is correct and should work assuming that the filters you are passing are valid.
To ensure that you are passing the correct data entity to the renderTemplateToStream method, you should check the data source of your template in Dynamics 365. Make sure that it is set to the correct entity that contains the data you want to populate the template with.
If you are still not getting any entity data, you should also check your filters to make sure that they are correctly filtering the data that you want to display in your report. You can test your filters by running them in a query or report to ensure that they are correctly selecting the data that you want to use.
Additionally, you may want to consider debugging your code by setting breakpoints and stepping through it to see where the issue might be occurring. This can help you identify any potential errors or issues in your code that may be causing the problem.
I hope this helps! Let me know if you have any further questions.
DAniele