Intro
In one of our we’ve shown how to add an image that was already available in D365FO to Docentric report templates:
Sometimes we would like to use images that are stored somewhere else, for example on SharePoint, on our Docentric report templates.
Working example
In this post we’ll show how to add an image banner to our Docentric report templates, but this time we’ll fetch the image from SharePoint.
-
First step is of course to have an image we want to use on a SharePoint location that the D365FO app has access to:
-
Next, we need to create a small custom class, that will extend the base DocDataSourceProviderBase class:
[ExtensionOf(classStr(DocDataSourceProviderBase))]
final class DocDataSourceProviderBase_Extension
{
protected void addGeneralDataSectionBaseCompanyInfo(DocXmlRecord _currentCompanyDataRecord, CompanyInfo _currentCompanyInfo)
{
next addGeneralDataSectionBaseCompanyInfo(_currentCompanyDataRecord, _currentCompanyInfo);
Bitmap bannerImage;
System.String fullPath = 'https://docentric.sharepoint.com/Test/Shared Documents/NenadSPTest/Docentric-banner.png';
System.String siteUrl = 'https://docentric.sharepoint.com/Test';
try
{
DocSharePointCredentials spCredentials = DocSharePointCredentials::constructFromSetup(fullPath);
using (System.IO.Stream imageStream = DocSharePointHelperV3::getFileContentByUrl(fullPath, siteUrl, spCredentials))
{
bannerImage = DocGlobalHelper::convertMemoryStreamToContainer(imageStream);
}
}
catch
{
// This is needed to ignore errors that can happen when attempting to get the image from SharePoint, in which case, the method will silently fail, but the report will still be printed.
Global::exceptionTextFallThrough();
}
_currentCompanyDataRecord.addCalculatedField('Banner', bannerImage, 'Company Banner');
}
}
-
Now, we’ll need to generate the DDSP of the report we’re designing, in this example Sales Invoice, by firstly setting the Print destination of the report to be the Docentric Generate DS:
-
Then we can simply print the report and we’ll get the DDSP file:
-
Lastly, we will load the this DDSP into our Docentric template that we’re designing:
This is all that is needed to make the Banner image available in the Docentric template:
Outro
In this example we added data to the GeneralData/CompanytInfo section by using the addGeneralDataSectionBaseCompanyInfo(), but we can also add info to the other sections found under GeneralData by using the following methods:
- addGeneralDataSectionBaseWorkerInfo() – to add data to the CurrentWorker section.
- addGeneralDataSectionBaseMiscInfo() – to add data to the Misc section.
- addGeneralDataSectionBase() – to add data to the base GeneralData section.