In the Classic client, you can show or hide a section of a report based on a condition. For example, section A of a report is shown only for customers that have a Customer No. value in a given range. You can show or hide a section conditionally by calling CurrReport.SHOWOUTPUT(<expr>) in the OnPreSection trigger of the report. If expr is false, then the section is not displayed, and the SourceExpr values of the controls in the section are not evaluated.

You can also have a report with a control that calls a function in the conditionally displayed section. For example, a SourceExpr value of a control can call the CLOSINGDATE function on a date variable. The OnPreSection trigger of the report determines whether the section is displayed. The expression that is evaluated in CurrReport.SHOWOUTPUT(<expr>) and the date variable on which the CLOSINGDATE function is called are related so that if expr is true, then the date variable is an initialized variable. If expr is false, then the date variable is not initialized. If CLOSINGDATE is called on a variable that is not initialized, then the a run-time error occurs. However, in this case, expr is false, so the section is not displayed, and the SourceExpr of the control is not evaluated. The CLOSINGDATE function is not called.

In a client report definition (RDLC) layout, section triggers are not supported. When you create an RDLC layout suggestion for this report, the OnPreSection trigger is not included. Additionally, all data for the report is calculated on Microsoft Dynamics NAV Server before it is sent to the client to be displayed. The CLOSINGDATE function is called even if the date variable is not initialized, and a run-time error occurs.

To redesign the RDLC report layout for this type of report, you must write C/AL code for the SourceExpr value that verifies the data that is passed to the function and then calls the function. That way, CLOSINGDATE is called only if the data is initialized. Otherwise, the SourceExpr value evaluates to null.

To redesign code that is executed conditionally

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

  2. In Object Designer, click Report, select a report that you want to modify, and then click Design.

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

  4. In the C/AL Globals window, click the Functions tab.

  5. Enter a name for the new function. For example, enter SafeClosingDate to create a function to use instead of the CLOSINGDATE function.

  6. Click Locals to define the parameters, return value, local variables, and text constants in the C/AL Locals window. For example, define the following values:

    • On the Parameters tab, enter SourceDate for the name of a parameter and enter Date for the DataType.

    • On the ReturnValue tab, enter NewClosingDate for the name of the return value and enter Date for the return type.

    • On the Variables tab, enter UndefinedDate for the name of a variable and enter Date for the data type.

  7. Close the C/AL Locals window.

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

  9. In the C/AL Editor, enter code for the new function that you defined. For example, enter the following code for the VerifyClosingDate function.

      CopyCode imageCopy Code
    UndefinedDate := 0D;
    IF(SourceDate = UndefinedDate) THEN
    	EXIT(UndefinedDate);
    ELSE
    	EXIT(CLOSINGDATE(SourceDate));
    
  10. If you have not transformed the report to an RDLC report layout, then complete the following steps:

    1. On the View menu, click Sections.

    2. In the section that is displayed based on a condition, select the control that calls the function that you want to replace, and on the View menu, click Properties.

    3. In the Properties window, in the SourceExpr field, enter the function call to the new function that you created. For example, enter SafeClosingDate(<Date variable>).

    4. Save and compile the report.

    5. On the Tools menu, click Create Layout Suggestion to create an RDLC layout for the report.

  11. If you have already transformed the report to an RDLC report layout, then complete the following steps:

    1. On the View menu, click Layout.

    2. On the View menu, select the control that calls the function that you want to replace.

    3. Replace the call to the CLOSINGDATE function with a call to the SafeClosingDate function.

See Also