Troubleshooting: Actions That Call Subforms

The form transformation tool has built-in rules for transforming menu items. The built-in rules specify that a menu item is transformed to the Actions menu on the main page except in the following cases.

  • If the menu item calls a subform and can be moved to the subform without changing functionality, then the menu item is transformed to the subform.

  • If a menu item on the main form calls a subform but the code cannot be moved to the subform without changing the functionality, then the menu item is not moved, and the issue is included in the form transformation log file. To resolve this issue, you must rewrite the code for the menu item.

The following illustration shows a main form that calls a subform. The Get Price function in this form depends on the item that is selected in the line of the subform.

Dd568714.Local_-1745843676_nav_ft_troubleshooting_formsubform(en-us,NAV.60).png

If you have a custom form that has a menu item that depends on the record that is selected in the subform, then you may need to rewrite the code. The following procedure describes how to rewrite code for an action on a main form that calls a subform.

To complete this procedure, you will need:

To modify an action that depends on a subform

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

  2. In Object Designer, click Form, select the subform on which the function that you want to redesign depends, and then click Design.

  3. On the View menu, click C/AL Code.

  4. Find the function that the main form calls. For example, on a form that gets the price of the item that is selected on the subform, you may have a ShowPrices function with an input SalesHeader parameter and with the following code.

    CLEAR(SalesPriceCalcMgt);
    SalesPriceCalcmgt.GetSalesLinePrice(SalesHeader,Rec);
    
  5. In the View menu, click C/AL Locals. On the Variables tab, create a new local variable called SalesHeader that has a DataType of Record and Subtype of Sales Header. On the Parameters tab, remove the parameter from the function.

  6. In the C/AL Editor, add code that gets the information from the table for the line that is selected in the subform. Now, your modified ShowPrices function has no parameters. It uses the SalesHeader local variable that you created in stepĀ 5 instead of using a SalesHeader parameter that is passed to the function. ShowPrices has the following code.

    SalesHeader.GET("Document Type","Document No.");
    CLEAR(SalesPriceCalcMgt);
    SalesPriceCalcMgt.GetSalesLinePrice(SalesHeader,Rec);
    
  7. Close the C/AL Editor.

  8. To close and compile the subform, close the subform in Form Designer. In the Save Changes window, confirm that the Compile check box is selected, and then click Yes.

  9. In Object Designer, click Form, select the main form that you want to redesign, and then click Design.

  10. In Form Designer, click the Functions command button.

  11. In the View menu, click Menu Items.

  12. In Menu Designer, select the line for the menu item that you want to redesign.

  13. On the View menu, click C/AL Code.

  14. In the OnPush trigger, change the code to call the function that you modified, which does not have any parameters. For example, if you modified the ShowPrices function, then change the following code.

    // Old code
        SalesHeader.Get("Document Type","No.");
        CurrForm.ShowPrices(SalesHeader);
    // New code
        CurrForm.SalesLines.FORM.ShowPrices
    
  15. Close the C/AL Editor.

  16. To close and compile the subform, close the subform in Form Designer. In the Save Changes window, confirm that the Compile check box is selected, and then click Yes.

See Also

Tasks

How to: Retransform Forms

Concepts

Reviewing the Form Transformation Log Output File