The AL developer preview is still evolving with frequent updates. Follow us on the Dynamics NAV Team Blog for the announcements.
RUN Method (Codeunit)
Loads and executes the unit of AL code you specify. To use this method, you can specify a table associated with the codeunit when you defined the codeunit properties. This allows you to pass a variable with the method. The transaction that the codeunit contains is always committed due to the Boolean return value.
[Ok :=] Codeunit.RUN(VAR Record)
Identifies the codeunit that you want to run.
This parameter is not always optional. If you specify a table associated with the codeunit, then you can select a record. If you do not specify a table, then you cannot specify a record. However, you must use this parameter to select a record if you attached a record to the codeunit when you defined its properties.
This parameter is a record data type.
Property Value/Return Value
If you do not include the optional return value and an error occurs while the codeunit is running, then the AL code that called this codeunit will terminate.
If you include the return value and an error occurs, then the calling AL code continues to run. This means that you must handle any errors. If you include the return value, the variables used in the codeunit will be cleared before and after the codeunit runs.
true if no errors occurred; otherwise, false.
This example runs two codeunits. The first uses a record parameter. The second is defined without a source table. This example requires that you create the following variables.
AccountRecord.INIT; IF NOT FiscalYearCloseInstance.RUN(AccountRecord) THEN ERROR('Codeunit run failed (with record).'); IF NOT AppMgmtInstance.RUN THEN ERROR('Codeunit run failed.');