Making Body in Document-Mailing Multilingual

The new Document-Mailing feature introduced in NAV 2016 is great. But the only way to have the email body in the customers language, is by generating all the body text as ML in the dataset or by making x number of copies of the report.
Wouldn’t it be nice to just write multiple layouts in Word, and have them controlled by the Customers Language Code?

Here is how you do that, with minimal change in standard code.

Make a copy of Table 77, we will use it for Report, Language and Layout relation.
Delete fields 2, 7, 19 and 20, so it looks like this.
Delete all functions and trigger code, and update these 3 fields triggercode like this.
Set Primary Key to Usage, Language Code

Report ID - OnValidate()
CALCFIELDS("Report Caption");

Email Body Layout Code - OnValidate()
CALCFIELDS("Email Body Layout Description");

Email Body Layout Description - OnLookup()
IF CustomReportLayout.LookupLayoutOK("Report ID") THEN
 VALIDATE("Email Body Layout Code",CustomReportLayout.Code);

Create a function i the table called FindEmailBodyUsage and add these Locals.
Add this code to the function.

FindEmailBodyUsage(ReportUsage : Integer;CustNo : Code[20];VAR TempReportSelections : Record "Report Selections") : Boolean
// Get Customer Language Code
LanguageCode := Customer."Language Code";

IF EmailBodyManagement.GET(ReportUsage, LanguageCode) THEN BEGIN
 // Get the "real" ReportSelection at copy it to our TempReportSelection
 ReportSelections.GET(ReportUsage, 1);
 TempReportSelections := ReportSelections;
 // Then replace the Body Layout Code with the one from your table, that is Language specific
 TempReportSelections."Email Body Layout Code" := EmailBodyManagement."Email Body Layout Code";


Go to Table 77 and find the function called GetEmailBody.
Add a local variable to the function, pointing at your new table.
In the GetEmailBody function you replace the standard call to FindEmailBodyUsage with a call to your own function.
Lets create 2 word layouts for Report 206, one with Danish text, and one with English
Set Report Selection – Sales for Invoice to Report 206
Add the 2 Word layouts to your new table.
When you select S.Invoice the Report ID is filled from the Report Selection table.
Just add Language Code and the Layout to go with it.
Then Email a posted invoice from 2 Customers, one with DAN and one with ENU language code.
8  9
Voila, with only changing 1 line of code in standard objects.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s