Export (0) Print
Expand All

Walkthrough: Redesigning the Acc. Schedule Overview Form

Microsoft Dynamics Nav 2009

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.

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.

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.

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

  1. In the Classic client, on the Tools menu, click Object Designer.

  2. In Object Designer, click Form, select form 490, Acc. Schedule Overview, and then click Design.

  3. One the File menu, click Save As.

  4. 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

  1. 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.

  2. Create a Table Box on the form. For more information, see How to: Create a Table Box.

  3. On the View menu, click Field Menu.

  4. 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.

  5. 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.

  6. On the View menu, click C/AL Globals.

  7. On the Variables tab, add a new variable by doing the following:

    1. In the Name field, enter ColumnValues.

    2. In the DataType field, select Decimal.

  8. To specify that the ColumnValues variable is an array, do the following:

    1. On the View menu, click Properties.

    2. In the ColumnValues - Properties window, in the Dimensions field, enter 12.

  9. In the C/AL Globals window, on the Variables tab, add a new variable by doing the following:

    1. In the Name field, enter ColumnCaptions.

    2. In the DataType field, select Text.

  10. To specify that the ColumnCaptions variable is an array, do the following:

    1. On the View menu, click Properties.

    2. In the ColumnCaptions - Properties window, in the Dimensions field, enter 12.

  11. In each of the 12 additional columns, do the following:

    1. Select the column, and then on the View menu, click Properties.

    2. In the SourceExpr property, enter ColumnValues[<column number>] where <column number> is the number of the column from 1 to 12.

    3. 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.

  12. In Form Designer, select the form, and then on the View menu, click C/AL Code.

  13. Modify the lines of code that use CurrForm.AccSchedMatrix.MatrixRec to use TempColumnLayout instead. For example, in the OnOpenForm function, change

    AccSchedManagement.OpenColumns(CurrentColumnName,CurrForm.AccSchedMatrix.MatrixRec);
    

    to

    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.

  14. In the Form - C/AL Editor window, add the following code to the OnOpenForm trigger.

    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.

  15. In the Form - C/AL Editor window, add the following code to the OnAfterGetRecord trigger to set the values of the cells.

    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;
    
  16. With the cursor in the OnAfterGetRecord trigger, on the View menu, click C/AL Locals.

  17. In the Form - OnAfterGetRecord - C/AL Locals window, on the Variables tab, enter a new variable by doing the following:

    1. In the Name field, enter ColumnNo.

    2. In the DataType field, select Integer.

  18. On the View menu, click C/AL Globals.

  19. In the C/AL Globals window, enter a new array variable by doing the following:

    1. In the Name field, enter ColumnLayoutArr.

    2. In the DataType field, select Record.

    3. In the Subtype field, enter Column Layout.

    4. On the View menu, click Properties.

    5. 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

  1. 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.

  2. 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.

    NoteNote

    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.

  3. 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.

  4. On the General tab, right-click the section in which the text boxes are located, and then click Paste.

  5. On the Options tab, right-click the Show Error text box, and then click Cut.

  6. On the Options tab, right-click the Show Error label, and then click Cut.

  7. Delete the Options tab. To do this:

    1. Select the tab control, and then on the View menu, click Properties.

    2. In the Properties window, in the PageNames property, delete Options from the value. The resulting value of the PageNames property is General, Dimension Filters.

  8. 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:

    1. On the View menu, click Toolbox.

    2. In the Toolbox, select the Text Box icon.

    3. In the Toolbox, select the Add Label icon.

    4. In Form Designer, click and drag to add a text box with a label.

    5. Select the text box, and then on the View menu, click Properties.

    6. 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.

    7. In the Caption property, enter View by.

    8. Delete the option button controls at the bottom of the form.

    9. 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.

      FindPeriod('');
      
  9. Resize the section and arrange the controls as necessary.

  10. 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:

    1. Select the Previous Column command button control, and then on the View menu, click C/AL Code.

    2. In the OnPush trigger, delete the existing code and add the following.

      AdjustColumnOffset(-1);
      
    3. Select the Next Column command button control, and then on the View menu, click C/AL Code.

    4. In the OnPush trigger, delete the existing code and add the following.

      AdjustColumnOffset(1);
      
    5. On the View menu, click C/AL Globals.

    6. On the Functions tab, on a new line, enter AdjustColumnOffset, and then click Locals.

    7. 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.

    8. 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.

    9. In the C/AL Globals window, on the Function tab, on a new line, enter UpdateColumnCaptions, and then click Locals.

    10. 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.

    11. 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.

    12. 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.

    13. In the C/AL Editor, enter the following code in the AdjustColumnOffset function.

      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;
      
    14. In the C/AL Editor, enter the following code in the UpdateColunnCaptions function.

      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] := ' ';
      
      NoteNote

      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.

  11. On the File menu, click Save. Confirm that the Compile check box is selected, and then click OK.

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:

Community Additions

ADD
Show:
© 2014 Microsoft