Word Layout for Email Body
rjsf
Member Posts: 17
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?
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?
0
Answers
-
You can find what you need in standard code, look at table 77 and codeunit 60.
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/Follow me on my blog juhl.blog0 -
Hi Juhl, thanks. Actually I already explored that route, but unfortunately the report does not fall on any of the preexisting Report Usage Types in table 77. It will actually be more difficult to use the routines in that table just to send a custom Word Layout email. All we need is to send a custom Word Layout in the background and we do not need the fancy UI from the standard routines.
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.
0 -
Look at GetEmailBody in TAB77, i just used it last week, no problem.
If you need it in Outlook, you need to move the file to the client.ReportSelections.GetEmailBody(ServerEmailBodyFile,ReportSelections.Usage,SalesInvoiceHeader,SalesInvoiceHeader."Bill-to Customer No.",EmailAdress); Body := GetBodyText(ServerEmailBodyFile);
LOCAL GetBodyText(ServerFilePath : Text) Value : Text IF (ServerFilePath <> '') AND FileManagement.ServerFileExists(ServerFilePath) THEN BEGIN TempBlob.INIT; FileManagement.BLOBImportFromServerFile(TempBlob,ServerFilePath); TempBlob.Blob.CREATEINSTREAM(BlobInStream); BlobInStream.READ(Value); ERASE(ServerFilePath); END;
Follow me on my blog juhl.blog0 -
Did you set the "DocumentVariant : Variant" correctly? I can remember that I got a similar error-message, caused by a wrong DocumentVariant.0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 610 NAV Courses, Exams & Certification
- 1.9K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 251 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions
