How to update G/L Entry and CLE in Sales Order Prepayment?

Aravindh_NavisionAravindh_Navision Member Posts: 258
Hi Friends,

I have created a new option field (Name: OptionField with optionstrings Blank,Option1, Option2) in Sales Order (Table: "Sales Header") with an field ID 50000. With the same field ID, field name and options value, I created a new field in Posted Sales Invoice (Table: "Sales Invoice Header"), "G/L Entry", "Cust. Ledger Entry" tables. I need to update the field value in the above mentioned tables after posting the sales order.

To update in Posted Sales Invoice, NAV will take care automatically by matching the field ID. To update in "G/L Entry" and "Cust. Ledger Entry", I wrote a code in PostGLAcc() function in the codeunit "Gen. Jnl.-Post Line" (codeunit 12).
WITH GenJnlLine DO BEGIN
  IF "Delayed Unrealized VAT" AND "Realize VAT" THEN
    IF ("Applies-to Doc. No." <> '') OR ("Applies-to ID" <> '') THEN
      PostDelayedUnrealizedVAT;

  // Post G/L entry
  InitGLEntry(
    "Account No.","Amount (LCY)",
    "Source Currency Amount",TRUE,"System-Created Entry");
  IF NOT "System-Created Entry" THEN
    IF "Posting Date" = NORMALDATE("Posting Date") THEN
      GLAcc.TESTFIELD("Direct Posting",TRUE);
  GLEntry."Gen. Posting Type" := "Gen. Posting Type";
  GLEntry."Bal. Account Type" := "Bal. Account Type";
  GLEntry."Bal. Account No." := "Bal. Account No.";
  GLEntry."No. Series" := "Posting No. Series";

  GLEntry."Option Field" := "Option Field"; // Newly assigned option field value

  IF "Additional-Currency Posting" =
     "Additional-Currency Posting"::"Additional-Currency Amount Only"
  THEN BEGIN
    GLEntry."Additional-Currency Amount" := Amount;
    GLEntry.Amount := 0;
  END;
  InitVat;
  InsertGLEntry(TRUE);
  IF EntryType = GLEntry."Entry Type"::Definitive THEN BEGIN
    PostJob;
    PostVAT;
  END;
END;

and in PostCust() function in the same codeunit "Gen. Jnl.-Post Line" (codeunit 12).
WITH GenJnlLine DO BEGIN
  IF Cust."No." <> "Account No." THEN
    Cust.GET("Account No.");
  Cust.CheckBlockedCustOnJnls(Cust,"Document Type",TRUE);

  IF "Posting Group" = '' THEN BEGIN
    Cust.TESTFIELD("Customer Posting Group");
    "Posting Group" := Cust."Customer Posting Group";
  END;
  CustPostingGr.GET("Posting Group");
  CustPostingGr.TESTFIELD("Receivables Account");

  DtldCustLedgEntry.LOCKTABLE;
  CustLedgEntry.LOCKTABLE;

  CustLedgEntry.INIT;
  CustLedgEntry."Customer No." := "Account No.";
  CustLedgEntry."Posting Date" := "Posting Date";
  .
  .
  .
  CustLedgEntry.Prepayment := Prepayment;

  CustLedgEntry."Option Field" := "Option Field"; // Newly assigned option field value

  .
  .
  .
This is working fine.

Issue: I got struck when I make a Sales Prepayment. From Sales Order form > Posting (button) > Prepayment > Post Prepayment Invoice. It is calling a codeunit "Sales-Post Prepayment (Yes/No)" (codeunit 443), which again calls functions in "Sales-Post Prepayments" (codeunit 442).

The option field value is not getting updated in "G/L Entry" and "Cust. Ledger Entry" tables. I tried debugger, but I could not able to make it up where this activity is happening.

Can anyone tell me the codeunit/function of where it is getting hitted and assigning the values?

Thanks in advance,
Aarvi.
Sign In or Register to comment.