Editing codeunit 80 — Dynamics NAV 2018

Insight codeunit modifications cause the Window variable to be invoked only when the GUI is allowed to prevent issues when running Insight integrations. Additional modifications publish the insertion of Sales objects.

Add the appropriate Insight code changes to the codeunit design. Carefully editing codeunit 80 can preserve any changes that have already been made to it.

The file COD80.txt resides in the NAS working directory subfolder that holds the Dynamics NAV localization, database version, and build, for example: ..\Microsoft Dynamics NAV\110\Service\Add-Ins\Scribe\W1.11.0.19394.

To edit the codeunit, use the .txt file that matches your version of Microsoft Dynamics NAV. TIBCO suggests that you review COD80.txt before editing codeunit 80.

Correcting the Window variable error

Warning: When running the PostSalesOrder custom action which wraps Codeunit 80 Sales-Post, you may get an error message saying that you cannot use C/AL variables of type DIALOG when running the Application Server. This error is caused by the global variable Window used in OnRun trigger.

To correct the Window variable error

Note: Dynamics NAV C/AL code requires BEGIN and END keywords encapsulating compound statements. Where the “IF GUIALLOWED THEN:” statement is added, if there are multiple lines of C/AL Code invoking the Window variable, then the BEGIN and END keywords must be used to encapsulate all of lines of code.

Making other changes to codeunit 80

After you correct the Window variable error, make the remaining required edits to codeunit 80.

To edit codeunit 80

  1. Open the Microsoft Dynamics NAV Development Environment.
  2. Click Tools > Object Designer. The Object Designer appears.
  3. Click Codeunit (Codeunit Icon).
  1. From the list of codeunits, select codeunit 80, Sales-Post.
  2. Click Design. The C/AL Editor appears.
  3. Click anywhere in the OnRun section of the open codeunit.
  4. On the Microsoft Dynamics NAV 2018 Development Environment, click View > C/AL Locals.
  5. On the Variables tab, add the following local variables:
    NameDataTypeSubtypeLength
    ScribePublisher CodeunitScribe Publisher 
    RecRefRecordRef  
  6. Close the C/AL Locals window. You return to the C/AL Editor.
  7. In the OnRun section:

    Before:

    OnAfterPostSalesDoc(

    Rec,GenJnlPostLine,SalesShptHeader."No.",ReturnRcptHeader."No.",SalesInvHeader."No.",SalesCrMemoHeader."No.");

    Add:

    IF NOT SalesHeader.IsCreditDocType THEN BEGIN
    //*****Scribe Begins*****
    // Trigger ScribePublisher
    RecRef.GETTABLE(SalesInvHeader);
    ScribePublisher.PublishInsertion(RecRef);
    //*****Scribe Ends*****
    END;

  8. When you are done, save the codeunit and make sure that it compiles without errors. Make a note of the codeunit's new revision level.

See also

Editing the codeunits — Dynamics NAV 2018

Next step