Workflow approval emails in Dynamics 365 Finance and Operations (D365FO) automatically notify approvers when documents require action, streamlining processes by sending alerts for tasks like approval, rejection, or delegation.
In my case, while working with the Vendor Invoice approval journal, there was a requirement to include an attachment along with the email notification. However, as we know, standard workflow emails in D365FO do not support sending attachments. Therefore, a custom solution needed to be explored.
Since Power Automate can capture workflow approval actions, I leveraged this functionality and extended F&O with custom logic to automatically identify and download the attachment uploaded to the journal.
Let us explore the solution:
My idea was to extract the document Id from DocuRef table using the LedgerJournalTrans Recid. With this DocumentId, we can retrieve the attachment .
The first step starts with Business event trigger for Vendor Invoice Journal.
Using Parse_Json step, response from the business event is parsed
I had to include the steps for mail contents using the workflow instructions. These steps will be covered later. In this post, let us focus on getting the attachment and sending it in the approval emails.
Next step is to validate the workflow.
In order to get the Document Id , get the LedgerjournalLine record . In my case, there were only two lines in the journal, one of type vendor and other as Ledger. So I am sending a filter as Vendor in my Odata call.
Using Parse_Json , the response from the Get LedgerJournal Record is parsed.
The document Id is retrieved
public static DocuDocumentId fetchDocumentId( DataAreaId _company,RefRecId _ledgerJournalTransRecId)
{
DocuRef docuRef;
DocuDocumentId documentId ;
select firstonly docuRef
where docuRef.RefRecid == _ledgerJournalTransRecId
&& docuRef.ActualCompanyId == _company;
if(docuRef)
{
documentId = docuRef.documentId;
}
return documentId;
}
Now, we have the document Id, we can fetch the details of attachment .
[SysODataActionAttribute('fetchAttachmentURLFromDocumentId',false)]
public static str fetchAttachmentURLFromDocumentId(DocuDocumentId _documentId, DataAreaId _company)
{
DocuRef docuRef;
str getURL ;
select firstonly docuRef
where docuRef.DocumentId == _documentId
&& docuRef.ActualCompanyId == _company;
if(docuRef)
{
getURL = File::SendFileToTempStore(DocumentManagement::getAttachmentStream(docuRef)
,ERDocuRef_Extension::filename(docuRef)
,classStr(FileUploadTemporaryStorageStrategy)
,true);
}
return getURL;
}
Download the contents.
File name is fetched .
public static str fetchFileDetails(DocuDocumentId _documentId, DataAreaId _company)
{
DocuRef docuRef;
str filedetails ;
select firstonly docuRef
where docuRef.DocumentId == _documentId
&& docuRef.ActualCompanyId == _company;
if(docuRef)
{
filedetails = docuRef.originalFileName();
}
return filedetails;
}
If the condition of ‘Execute action’ is true, then send an approval email along with the attachment is sent using ‘start and wait for approval‘ action in Power automate
Next step is to add the ‘Complete’ using ‘Execution action’ which sends the approval response to D365FO
Both Target and RunAs User should be mentioned in this step.
In my case, I have ‘WorkFlowItemOwner’ in both the parameters.
This is the design template for sending an attachment along with the workflow approval email.
Hope it helps..
Original Post https://anithasantosh.wordpress.com/2025/09/17/attachment-in-d365fo-workflow-approval-emails/