Hello, I've been trying to put together some code to send a custom report via email. This email is a "Debit Notification" sent from a custom function to notify customers, so I could not use the built-in email functions. The client requested the format be Word. I used pointers from this blog post on how to do it:
https://saurav-nav.blogspot.com/2017/08/microsoft-dynamics-nav-2017-email-from_21.html
My understanding is that the Word Layout is a BLOB that must first be saved as HTML format via REPORT.SAVEASHTML, and then used as the body for the E-mail. I created a function below to generate the HTML, given the record, the Layout Code and the Report ID:
LOCAL GenerateEmailBody(DocumentVariant : Variant;ReportID : Integer;VAR BodyFilePath : Text;LayoutCode : Code[20])
BodyFilePath := COPYSTR(FileManagement.ServerTempFileName('html'),1,250);
ReportLayoutSelection.SetTempLayoutSelected(LayoutCode);
REPORT.SAVEASHTML(ReportID, BodyFilePath, DocumentVariant);
ReportLayoutSelection.SetTempLayoutSelected('');
However, I'm getting an error "An invalid field or attribute has been specified for the 'Format' property", and it occurs when REPORT.SAVEASHTML is called. Am I doing this right, or is there another way to send Word Layouts as bodies in email?
Answers
Also I wrote this extending on standard function, maybe you can be inspired https://juhl.blog/2017/11/05/making-body-in-document-mailing-multilingual/
So that is why I already built this function and I just need help to find out why I'm getting the error message on SAVEASHTML.
If you need it in Outlook, you need to move the file to the client.