If you have worked on a Role Tailored Layout and wanted to show a report without decimals you have most likely seen that the AutoFormatType option that we have in the Dynamics NAV 2009 R2 Classic Client does not work in the Role Tailored Layout
If you study the dataset that the Role Tailored Client delivers to the report the numbering format is not related to the AutoFormatType. Why Microsoft chose to ignore this in this release I will never know.
In Iceland we do not use decimals in currency amounts. However, when printing currency amount they are supposed to show decimals. So I created my own AutoFormat solution.
The first step is to create a codeunit that uses the same logic as the AutoFormatType and delivers the Role Tailored Layout number format.
[code]OBJECT Codeunit 50012 RTC Decimal Format
{
OBJECT-PROPERTIES
{
Date=29.11.12;
Time=09:47:37;
Version List=Dynamics.is;
}
PROPERTIES
{
OnRun=BEGIN
END;
}
CODE
{
VAR
GLSetup@1100408003 : Record 98;
Currency@1100408004 : Record 4;
SetupRead@1100408000 : Boolean;
PROCEDURE AutoFormatLayout@12(AutoFormatType@1000 : Integer;AutoFormatExpr@1001 : Text[80]) : Text[80];
VAR
AmountDecimalPlaces@1100408000 : Text[30];
BEGIN
IF AutoFormatType = 0 THEN
EXIT(”);
IF NOT GetSetup THEN
EXIT(”);
CASE AutoFormatType OF
1: // Amount
IF AutoFormatExpr = ” THEN
EXIT(CreateNumberFormat(GLSetup."Amount Decimal Places"))
ELSE BEGIN
IF GetCurrency(COPYSTR(AutoFormatExpr,1,10)) AND
(Currency."Amount Decimal Places" <> ”)
THEN
EXIT(CreateNumberFormat(Currency."Amount Decimal Places"))
ELSE
EXIT(CreateNumberFormat(GLSetup."Amount Decimal Places"));
END;
2: // Unit Amount
IF AutoFormatExpr = ” THEN
EXIT(CreateNumberFormat(GLSetup."Unit-Amount Decimal Places"))
ELSE BEGIN
IF GetCurrency(COPYSTR(AutoFormatExpr,1,10)) AND
(Currency."Unit-Amount Decimal Places" <> ”)
THEN
EXIT(CreateNumberFormat(Currency."Unit-Amount Decimal Places"))
ELSE
EXIT(CreateNumberFormat(GLSetup."Unit-Amount Decimal Places"));
END;
10: EXIT(”);
END;
END;
LOCAL PROCEDURE CreateNumberFormat@1100408000(AmountDecimalPlaces@1100408000 : Text[30]) RTCFormat : Text[30];
VAR
Pos@1100408001 : Integer;
DecimalPlaces@1100408002 : Integer;
BEGIN
Pos := STRPOS(AmountDecimalPlaces,’:’);
IF Pos > 0 THEN
AmountDecimalPlaces := COPYSTR(AmountDecimalPlaces,Pos + 1);
IF NOT EVALUATE(DecimalPlaces,AmountDecimalPlaces) THEN
DecimalPlaces := 0;
RTCFormat := ‘#,##0’;
IF DecimalPlaces > 0 THEN
RTCFormat := RTCFormat + ‘.’ + PADSTR(”,DecimalPlaces,’0′);
END;
LOCAL PROCEDURE GetSetup@10015() : Boolean;
BEGIN
IF SetupRead THEN EXIT(TRUE);
SetupRead := GLSetup.GET;
EXIT(SetupRead);
END;
LOCAL PROCEDURE GetCurrency@1(CurrencyCode@1000 : Code[10]) : Boolean;
BEGIN
IF CurrencyCode = Currency.Code THEN
EXIT(TRUE);
IF CurrencyCode = ” THEN BEGIN
CLEAR(Currency);
Currency.InitRoundingPrecision;
EXIT(TRUE);
END;
EXIT(Currency.GET(CurrencyCode));
END;
BEGIN
END.
}
}
[/code]
Then I implement this on the Classic Section, example in Report 105. First I add my codeunit to Globals.
Then I insert two hidden fields in the Sections.
The first field for the LCY format
and the second field for the current currency format
This adds the fields CurrencyAutoFormat and LCYAutoFormat to my dataset.
The final step is to replace the default Format property in the Role Tailored Layout. I look at the field CustBalanceDue_1_ and see that this field can in some cases show currency amount and sometimes it shows LCY amounts. This is determined by the PrintAmountsInLCY value. I then set the Format property for this field to “=iif(Fields!PrintAmountsInLCY.Value,Fields!LCYAutoFormat.Value,Fields!CurrencyAutoFormat.Value)”
Next I look at the sum for this field. This sum is always shown in the local currency. I then set the Format property for this field to “=First(Fields!LCYAutoFormat.Value)”.
This way I have implemented the AutoFormatType functionality to the Role Tailored Layout.