The following walkthrough demonstrates the process of redesigning a matrix form so that it uses a table box control instead of a matrix box control. The matrix box control is not supported on the RoleTailored client, and you cannot transform a form with a matrix box control to a page by using the form transformation tool. You must redesign the matrix form and then transform the redesigned form to a page.
About This Walkthrough
This walkthrough illustrates the following tasks:
-
Creating a copy of the original matrix form and saving the copy as the redesigned form.
-
Replacing the matrix box control with a table box control on the redesigned form.
-
Modifying controls on the form that work with the table box.
Prerequisites
To complete this walkthrough, you will need:
-
Microsoft Dynamics NAV 2009 with a developer license.
-
The CRONUS International Ltd. demo data company.
Story
Viktor is a Microsoft Certified Partner who is working with CRONUS International to transform their forms to pages in Microsoft Dynamics NAV 2009 SP1. CRONUS International has several forms that use matrix box controls, and Viktor knows that he must redesign these forms before he can transform them to pages. He has looked at the redesigned matrix forms in Microsoft Dynamics NAV 2009 SP1, which are listed in the Redesigned Matrix Forms topic. He is familiar with how these forms were redesigned and is now ready to redesign form 490, Acc. Schedule Overview.
Redesigning the Acc. Schedule Overview Form
The first step for Viktor is to make a copy of the original matrix form so that he does not lose any code or functionality on the original form and can refer to the original form as he redesigns the copy.
To copy the original matrix form
-
In the Classic client, on the Tools menu, click Object Designer.
-
In Object Designer, click Form, select form 490, Acc. Schedule Overview, and then click Design.
-
One the File menu, click Save As.
-
In the Save As window, in the ID field, enter 50490. In the Name field, enter New Acc. Schedule Overview, and then click OK.
Viktor must remove the matrix box control from the form and replace it with a table box control. He must then add columns to the table and specify the values for the matrix-like columns in the table. To do that, he must create an array variable for the column values and an array variable for the column headers.
To replace the matrix box with a table box
-
In Form Designer for form 50490, delete the matrix box control. Right-click the top left corner of the Matrix Box, and then click Cut.
-
Create a Table Box on the form. For more information, see How to: Create a Table Box.
-
On the View menu, click Field Menu.
-
In the Field Menu, select both the Row No. and Description lines, click the form, and then click the table box to add these fields to the table.
-
Add 12 additional columns to the table. To add a column, add a Text Box control to the table. For more information, see How to: Add a Text Box without Using the Field Menu.
-
On the View menu, click C/AL Globals.
-
On the Variables tab, add a new variable by doing the following:
-
In the Name field, enter ColumnValues.
-
In the DataType field, select Decimal.
-
-
To specify that the ColumnValues variable is an array, do the following:
-
On the View menu, click Properties.
-
In the ColumnValues - Properties window, in the Dimensions field, enter 12.
-
-
In the C/AL Globals window, on the Variables tab, add a new variable by doing the following:
-
In the Name field, enter ColumnCaptions.
-
In the DataType field, select Text.
-
-
To specify that the ColumnCaptions variable is an array, do the following:
-
On the View menu, click Properties.
-
In the ColumnCaptions - Properties window, in the Dimensions field, enter 12.
-
-
In each of the 12 additional columns, do the following:
-
Select the column, and then on the View menu, click Properties.
-
In the SourceExpr property, enter ColumnValues[<column number>] where <column number> is the number of the column from 1 to 12.
-
In the CaptionClass property, enter '3,'+ColumnCaptions[<column number>] where <column number> is the number of the column from 1 to 12. For more information about this value, see CaptionClass Syntax.
-
-
In Form Designer, select the form, and then on the View menu, click C/AL Code.
-
Modify the lines of code that use CurrForm.AccSchedMatrix.MatrixRec to use TempColumnLayout instead. For example, in the OnOpenForm function, change
Copy Code AccSchedManagement.OpenColumns(CurrentColumnName,CurrForm.AccSchedMatrix.MatrixRec);
to
Copy Code AccSchedManagement.OpenColumns(CurrentColumnName,TempColumnLayout);
The CurrForm.AccSchedMatrix.MatrixRec is used in the following functions:
-
OnOpenForm trigger
-
OnAfterValidate trigger of the CurrentScheduleName text box
-
OnAfterValidate trigger of the CurrentColumnName text box
The reason for this change is that in the original form, the CurrForm.<matrix box control name>.MatrixRec contained the column table. In the redesigned form, there is no matrix box control. You use the temporary TempColumnLayout table instead. TempColumnLayout contains the column table.
-
-
In the Form - C/AL Editor window, add the following code to the OnOpenForm trigger.
Copy Code UpdateColumnCaptions;
This calls a function, which you add later in this walkthrough, to update the column captions when the form opens. Later in this walkthrough, you also call this function in the OnPush trigger of two new command buttons.
-
In the Form - C/AL Editor window, add the following code to the OnAfterGetRecord trigger to set the values of the cells.
Copy Code IF Totaling = '' THEN CLEAR(ColumnValues) ELSE IF TempColumnLayout.FINDSET THEN REPEAT ColumnNo := ColumnNo + 1; IF (ColumnNo > ColumnOffset) AND (ColumnNo - ColumnOffset <= ARRAYLEN(ColumnValues)) THEN BEGIN ColumnValues[ColumnNo - ColumnOffset] := AccSchedManagement.CalcCell(Rec,TempColumnLayout,UseAmtsInAddCurr); ColumnLayoutArr[ColumnNo - ColumnOffset] := TempColumnLayout; END; UNTIL TempColumnLayout.NEXT = 0;
-
With the cursor in the OnAfterGetRecord trigger, on the View menu, click C/AL Locals.
-
In the Form - OnAfterGetRecord - C/AL Locals window, on the Variables tab, enter a new variable by doing the following:
-
In the Name field, enter ColumnNo.
-
In the DataType field, select Integer.
-
-
On the View menu, click C/AL Globals.
-
In the C/AL Globals window, enter a new array variable by doing the following:
-
In the Name field, enter ColumnLayoutArr.
-
In the DataType field, select Record.
-
In the Subtype field, enter Column Layout.
-
On the View menu, click Properties.
-
In the Properties window, in the Dimensions field, enter 12.
-
Next, Viktor deletes the controls that he no longer needs, adds new controls to work with the table box, and rearranges controls to improve the layout of the form.
To arrange controls
-
In Form Designer, on the General tab, select the Previous Period and Next Period command button controls from the bottom of the form and move them to the top section near the text boxes.
-
On the General tab, delete the following controls:
-
Date Filter label
-
Date Filter text box
-
Budget Filter label
-
Budget Filter text box
These filters are available on the transformed page.
Note To view the filters on the transformed page, in the top right corner of the page, click the Customize button, and then select Limit Totals To.
-
-
On the Options tab, select both the Show Amounts in Add. Reporting Currency check box control and label, right-click the selection, and then click Cut.
-
On the General tab, right-click the section in which the text boxes are located, and then click Paste.
-
On the Options tab, right-click the Show Error text box, and then click Cut.
-
On the Options tab, right-click the Show Error label, and then click Cut.
-
Delete the Options tab. To do this:
-
Select the tab control, and then on the View menu, click Properties.
-
In the Properties window, in the PageNames property, delete Options from the value. The resulting value of the PageNames property is General, Dimension Filters.
-
-
Instead of the OptionButton controls at the bottom of the form that specify the period, add a text box to the top section of the General tab. To do this:
-
On the View menu, click Toolbox.
-
In the Toolbox, select the Text Box icon.
-
In the Toolbox, select the Add Label icon.
-
In Form Designer, click and drag to add a text box with a label.
-
Select the text box, and then on the View menu, click Properties.
-
In the Properties window, in the SourceExpr property, enter PeriodType. PeriodType is an Option variable and is the source expression for the OptionButton controls on the original form.
-
In the Caption property, enter View by.
-
Delete the option button controls at the bottom of the form.
-
Add code to the OnValidate trigger of the PeriodType text box. Copy the code from another matrix form that has been redesigned, such as form 9202, _Budget. The following code is from the OnValidate trigger in form 9202, _Budget.
Copy Code FindPeriod('');
-
-
Resize the section and arrange the controls as necessary.
-
Add Previous Column and Next Column command button controls. Copy these controls from another matrix form that has been redesigned, such as form 9202, _Budget, and then update the code. To update the code, do the following:
-
Select the Previous Column command button control, and then on the View menu, click C/AL Code.
-
In the OnPush trigger, delete the existing code and add the following.
Copy Code AdjustColumnOffset(-1);
-
Select the Next Column command button control, and then on the View menu, click C/AL Code.
-
In the OnPush trigger, delete the existing code and add the following.
Copy Code AdjustColumnOffset(1);
-
On the View menu, click C/AL Globals.
-
On the Functions tab, on a new line, enter AdjustColumnOffset, and then click Locals.
-
In the AdustColumnOffset - C/AL Locals window, on the Parameters tab, add a parameter. In the Name field, enter Delta. In the DataType field, select Integer.
-
In the AdustColumnOffset - C/AL Locals window, on the Variables tab, add a variable. In the Name field, enter OldColunnOffset. In the DataType field, select Integer.
-
In the C/AL Globals window, on the Function tab, on a new line, enter UpdateColumnCaptions, and then click Locals.
-
In the UpdateColumnCaptions - C/AL Locals window, on the Variables tab, enter a new variable. In the Name field, enter ColumnNo. In the DataType field, select Integer.
-
In the UpdateColumnCaptions - C/AL Locals window, on the Variables tab, enter a new variable. In the Name field, enter i. In the DataType field, select Integer.
-
In the C/AL Globals window, on the Variables tab, add a new variable. In the Name field, enter ColumnOffset. In the DataType field, select Integer.
-
In the C/AL Editor, enter the following code in the AdjustColumnOffset function.
Copy Code OldColumnOffset := ColumnOffset; ColumnOffset := ColumnOffset + Delta; IF ColumnOffset + 12 > TempColumnLayout.COUNT THEN ColumnOffset := TempColumnLayout.COUNT - 12; IF ColumnOffset < 0 THEN ColumnOffset := 0; IF ColumnOffset <> OldColumnOffset THEN BEGIN UpdateColumnCaptions; CurrForm.UPDATE(FALSE); CurrForm.UPDATECONTROLS; END;
-
In the C/AL Editor, enter the following code in the UpdateColunnCaptions function.
Copy Code CLEAR(ColumnCaptions); IF TempColumnLayout.FINDSET THEN REPEAT ColumnNo := ColumnNo + 1; IF (ColumnNo > ColumnOffset) AND (ColumnNo - ColumnOffset <= ARRAYLEN(ColumnCaptions)) THEN ColumnCaptions[ColumnNo - ColumnOffset] := TempColumnLayout."Column Header"; UNTIL (ColumnNo - ColumnOffset = ARRAYLEN(ColumnCaptions)) OR (TempColumnLayout.NEXT = 0); // Set unused columns to blank to prevent RTC to display control ID as caption FOR i := ColumnNo - ColumnOffset + 1 TO ARRAYLEN(ColumnCaptions) DO ColumnCaptions[i] := ' ';
Note Even though you replace the original code on these command button controls, we recommend that you copy them from a redesigned form, such as form 9202, and then replace the code so that the captions are identical. That way, you do not need to change the transformation input to promote the actions on the page.
-
-
On the File menu, click Save. Confirm that the Compile check box is selected, and then click OK.
Next Steps
Viktor's redesigned Acc. Schedule Overview form has the same functionality as the original form but does not use a matrix box control. Now Viktor can transform his redesigned form to a page. To transform the form he must:
-
Install the form transformation tool. For more information, see How to: Install the Form Transformation Tool.
-
Prepare the form transformation tool input. For more information, see Preparing Transformation Tool Input.
-
Transform the form. For more information, see Transforming Forms.
See Also
© 2010 Microsoft Corporation. All rights reserved.