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.
1
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.
2
3
4
Add this code to the function.

FindEmailBodyUsage(ReportUsage : Integer;CustNo : Code[20];VAR TempReportSelections : Record "Report Selections") : Boolean
// Get Customer Language Code
Customer.GET(CustNo);
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;
 TempReportSelections.INSERT;
 // 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";
 TempReportSelections.MODIFY;
END;

EXIT(TempReportSelections.FINDSET);

Go to Table 77 and find the function called GetEmailBody.
Add a local variable to the function, pointing at your new table.
5
In the GetEmailBody function you replace the standard call to FindEmailBodyUsage with a call to your own function.
6
Testing
Lets create 2 word layouts for Report 206, one with Danish text, and one with English
7
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.
10
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:

WordPress.com Logo

You are commenting using your WordPress.com 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