Editing codeunit 80 — Dynamics NAV 2009 R2

You must add the appropriate Insight code changes to the codeunit design. Carefully editing codeunit 80 can preserve any changes that may 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\60\Application Server\ScribeModifications\W1.6.02.32012.

To edit the codeunit, use the .txt file that matches your version of 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.

  1. Add the following statement before all instances of the Window variable in the design of codeunit 80:

    IF GUIALLOWED THEN

    For example, for the following statement:

    Window.UPDATE(1,STRSUBSTNO(Text007,"Document type","No.",SalesInvHeader."No."));

    Add:

    IF GUIALLOWED THEN
    Window.UPDATE(1,STRSUBSTNO(Text007,"Document type","No.",SalesInvHeader."No."));

    This eliminates the error message when the NAS runs codeunit 80.

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. In Dynamics NAV, click Tools > Object Designer. The Object Designer appears.
  2. In the Object Designer, click Codeunit (Codeunit Icon).
  3. From the list of codeunits, select the codeunit with the ID number 80, Sales-Post.
  4. Click Design. The C/AL Editor appears.
  5. Click anywhere in the OnRun section of the open codeunit.
  6. In Dynamics NAV, click View > C/AL Locals.
  7. Click the Variables tab, then add the following local variables:
    NameDataTypeSubtypeLength
    ScribePublisher CodeunitScribe Publisher 
    RecRefRecordRef  
  8. Close the C/AL Locals window. This returns you to the C/AL Editor.
  9. Click View > C/AL Globals. On the Variables tab, add the global variable:
    NameDataTypeSubtypeLength
    CustLedgEntry RecordCust. Ledger Entry 
  10. Save and close C/AL Globals, to return to the C/AL Editor.
  11. In the OnRun section:

    After:

    SalesInvHeader.INSERT;

    Add:

    // Trigger ScribePublisher
    RecRef.GETTABLE(SalesInvHeader);
    ScribePublisher.PublishInsertion(RecRef);

    After:

    IF "Bal. Account No." <> '' THEN BEGIN:

    Replace:

    Window.UPDATE(5,1);
    IF NOT IsOnlinePayment(SalesHeader) THEN
    PostBalancing(TempJnlLineDim,0)

    With:

    //*****SCRIBE BEGINS*****
    //Hide GUI window in NAS
    IF GUIALLOWED THEN
    Window.UPDATE(5,1);
    //*****SCRIBE ENDS*****


    CustLedgEntry.FINDLAST;
    GenJnlLine.INIT;
    GenJnlLine."Posting Date" := "Posting Date";
    GenJnlLine."Document Date" := "Document Date";
    GenJnlLine.Description := "Posting Description";
    GenJnlLine."Shortcut Dimension 1 CodeLeft" := "Shortcut Dimension 1 CodeLeft";
    GenJnlLine."Shortcut Dimension 2 CodeLeft" := "Shortcut Dimension 2 CodeLeft";
    GenJnlLine."Reason CodeLeft" := "Reason CodeLeft";
    GenJnlLine."Account Type" := GenJnlLine."Account Type"::Customer;
    GenJnlLine."Account No." := "Bill-to Customer No.";


    IF "Document Type" = "Document Type"::"Credit Memo" THEN
    GenJnlLine."Document Type" := GenJnlLine."Document Type"::Refund  
    ELSE
    GenJnlLine."Document Type" := GenJnlLine."Document Type"::Payment;
    GenJnlLine."Document No." := GenJnlLineDocNo;
    GenJnlLine."External Document No." := GenJnlLineExtDocNo;


    IF "Bal. Account Type" = "Bal. Account Type"::"Bank Account" THEN
    GenJnlLine."Bal. Account Type" := GenJnlLine."Bal. Account Type"::"Bank Account";  
    GenJnlLine."Bal. Account No." := "Bal. Account No.";
    GenJnlLine."Currency CodeLeft" := "Currency CodeLeft";
    GenJnlLine.Amount :=
    TotalSalesLine."Amount Including VAT" + CustLedgEntry."Remaining Pmt. Disc. Possible";  
    GenJnlLine."Source Currency CodeLeft" := "Currency CodeLeft";
    GenJnlLine."Source Currency Amount" := GenJnlLine.Amount;
    GenJnlLine.Correction := Correction;
    CustLedgEntry.CALCFIELDS(Amount);


    IF CustLedgEntry.Amount = 0 THEN
    GenJnlLine."Amount (LCY)" := TotalSalesLineLCY."Amount Including VAT"  
    ELSE
    GenJnlLine."Amount (LCY)" :=  
    TotalSalesLineLCY."Amount Including VAT" + 
    ROUND(  
    CustLedgEntry."Remaining Pmt. Disc. Possible" /  
    CustLedgEntry."Adjusted Currency Factor");  


    IF SalesHeader."Currency CodeLeft" = '' THEN
    GenJnlLine."Currency Factor" := 1  
    ELSE
    GenJnlLine."Currency Factor" := SalesHeader."Currency Factor";   
    GenJnlLine."Applies-to Doc. Type" := GenJnlLineDocType;
    GenJnlLine."Applies-to Doc. No." := GenJnlLineDocNo;
    GenJnlLine."Source Type" := GenJnlLine."Source Type"::Customer;
    GenJnlLine."Source No." := "Bill-to Customer No.";
    GenJnlLine."Source CodeLeft" := SrcCode;
    GenJnlLine."Posting No. Series" := "Posting No. Series";
    GenJnlLine."IC Partner CodeLeft" := "Sell-to IC Partner CodeLeft";
    GenJnlLine."Allow Zero-Amount Posting" := TRUE;
    GenJnlPostLine.RunWithCheck(GenJnlLine,TempJnlLineDim);

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

    Note: In the Object Designer, in the Version List column, edit the Release Sales Document codeunit's version to reflect the new revision level.

Next step

See also

Editing the codeunits — Dynamics NAV 2009 R2