Sending multiple attachments via email using Electronic Reporting
Published On: November 16, 2023Categories: Technical
Sending multiple attachments that are linked with some entities in Dynamics 365 FO, together with one main document has always been a hot topic for the clients. This functionality is not available through standard SSRS reporting and a customization is needed so it can be performed. Many clients use external ISV solutions that also provide implementation for it. But there is also a standard possibility that the user can set up to use this functionality, using an electronic reporting framework. This blog provides detailed step-by-step guidance on how it can be achieved. For this purpose, we will be performing the setup on the sales invoice document.
Import necessary configurations from Global repository
The first step is to import the necessary electronic reporting configurations from the global repository. If you have imported your configurations already and they are present in your local repository, skip this step. Go to Electronic reporting workspace > Select Repositories from the Microsoft configuration provider > Open the Global repository. Here you will see a list of all predefined Microsoft reports and configurations. Find the one that you need, select the latest version, and import it. In this scenario, we are importing the format Sales invoice (Excel).
Note that by importing the format, all necessary related configurations will be automatically imported as well, such as the model and the model mapping. So, you don’t need to worry about them.
2. Model configuration customization
The second step is to create a placeholder for the attachments in the model that is used by the format. Go to your local repository and find the model that is the parent of your format. In this scenario, that is the Invoice model. Go to Create configuration > DerivefromName: Invoice model, Microsoft > Create configuration.
Select the newly created configuration > Go to Designer > Select the root node where you want to add the node for attachments. In this scenario we want to send attachments linked to the invoice record, so we will choose InvoiceBase as a parent node. The node where you should add the attachments node in your scenario depends on the specified business goal you want to achieve. Select InvoiceBase node > Go to New > Set a name such as Attachments and item type equal to Record list. Inside of that node, create two more nodes: FileContent of type Container that will store the content of the attachments and FileName of type String that will be used for attachment names.
After you have completed this step, go back to the configuration repository > Select your derived model configuration > Change status to Complete.
3. Model mapping configuration customization
In this step we will map the newly created attachments node with the data source where those attachments are being stored. Locate the standard model mapping configuration that is being used for the report, in this case that is Invoice model mapping. Select the model mapping configuration > Create configuration > DerivedfromName: Invoice model mapping, Microsoft > Select targetmodel to be our newlycreatedmodel (AXM Invoice model (Test)) > Createconfiguration.
Go to the Designer of the newly created derived model mapping. In the data sources pane, find the data source where your attachments are linked to. In this case, we go to the $SalesInvoiceTmp_First because this is our main data source. In the left pane we select Functions > Calculatedfield and then we select Add.
We create a new calculated field named $CustInvoiceJourAttachments with the following formula:
If you need additional filtering or attachments of another type, you can modify the formula accordingly. After the calculated field is mapped, we bind the nodes in the model that we have created with corresponding nodes in the calculated field.
After you have completed this step, go back to the configuration repository > Select your derived model mapping configuration > Change status to Complete.
4.Format configuration customization
On same principle, create a derived format configuration with corresponding parameters. In this case, we are using the Sales invoice (Excel) format configuration. It is important to create the derived format based on our custom data model and the proper data model definition. Also set the latest data model version (in this case we only have one completed version of the model).
After the derived format has been successfully created, go to its Designer window. You can see only one root node. In this case, it’s named Sales invoice. Click Add root > Select Folder > Set the name parameter (e.g. Folder). You will see that now the already existing Excel node was set as a child of the Folder node. Select the Folder node > Click Add > Select Common/File > Set name as Attachments. Select the new node > Click Add > Select Binary contents > Set name as Content. Bind the Attachments and Content nodes correspondingly with Attachments and FileContent nodes from the model. Select the Attachments node on the format and in the File name formula designer set the path to the FileName node of the model.
NOTE: If you are not able to see the node type Common/File, in the action pane of the format designer change the type to All (in this case was predefined as Excel).
After you have completed this step, go back to the configuration repository > Select your derived format configuration > Change status to Complete.
5. Electronic Reporting Destination setup
In order to send the invoice together with the related attachments on the invoice record, we need to do a proper setup in the Electronic Reporting Destination form. Go to Organization administration > Electronic reporting destination > Click New > In Reference select the customized format configuration, in this case AXM Sales Invoice (Excel). In File destination, create two records for each component, Attachments and Sales invoice. Select both records and click on Group. Click on the Sales Invoice record and in Settings do a set up for the email template that will be generated. In the setup you can specify sender and recipient email address, subject and body.
With this setup, the whole procedure is completed, and you are ready to send multiple attachments via email to your desired destination.
Allow All Cookies
Third Party Embedes
Third-party cookies are cookies that are set by other websites, not this one. This website may use embedded content from other websites, such as YouTube or Google maps. Your consent is required to view content from these websites embedded on this site.