Dynamics 365 Business Central: How to add directly editable fields to Vendor Ledger Entries

Dynamics 365 Business Central

Hi, Readers.
Today I would like to briefly talk about a question I was asked last week, how to add directly editable fields to Vendor Ledger Entries.

As you might know, in addition to the setup data, there are two main types of data in Business Central, one is pre-posting data such as master data (Customers, Items…), and transactions data (Sales Orders, General Journals…), and the other is posted data such as Posted Sales Invoices, Customer/Vendor Ledger Entries, etc. In general, we can modify and delete the pre-posting data but we can’t edit and delete the posted data.

In Dynamics 365 Business Central: Can we insert/modify/delete posted data (Posted Documents & Posted Entries) via AL???, we briefly discussed how to insert/modify/delete posted data via AL.

And similar to what was mentioned in Change descriptions on G/L entries (MS Learn), we can choose Edit list on the Vendor Ledger Entries to modify some fields.

For example, Payment Method Code:

Due Date and other date fields. But due to the principle of data consistency, not many fields can be modified.

So, if we add new editable fields, can we edit them directly from this page? Let’s look at a simple example.

A strange behavior occurs at this time, the field can be modified, but it cannot be saved when saving. Specifically, the field value is cleared during validation.

Test video:

Why? This is because there is no permission to modify. We can create a simple Modify page and modify these new fields on it, similar to the following.
Dynamics 365 Business Central: How to extend the Posted Document Update page (A solution for editing Posted Document)

But is there a way to modify it directly? Yes, of cource. First let’s look at how the standard does it.
In the standard, this is done through the following special codeunit.

For example, codeunit 113 “Vend. Entry-Edit”

So we need to subscribe to the event in this standard codeunit, this time we use OnBeforeVendLedgEntryModify(VendLedgEntry, Rec).

For example,

Source code:

codeunit 50122 VLEModifyHandler
{
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Vend. Entry-Edit", OnBeforeVendLedgEntryModify, '', false, false)]
    local procedure "Vend. Entry-Edit_OnBeforeVendLedgEntryModify"(var VendLedgEntry: Record "Vendor Ledger Entry"; FromVendLedgEntry: Record "Vendor Ledger Entry")
    begin
        VendLedgEntry.Validate(ZYTest,FromVendLedgEntry.ZYTest);
        VendLedgEntry.Validate(ZYTest2,FromVendLedgEntry.ZYTest2);
    end;
}

This way we can modify it directly from the page.

Test video:

PS: This method also applies to Cust. Ledger Entry, G/L Entry and Item Ledger Entry

Very simple, so the next question is, is it possible to make standard fields editable as well? Yes, you can, but there are some restrictions.

First, because the Editable property cannot be customized, the fields in the table that define the Editable property as false cannot be modified.

Secondly, most fields such as “Original Amount” are Flowfields, which cannot be modified in the first place.

As for other fields, almost all of them can be modified in this way. For example, “External Document No.”
1. Add the field to the page.

2. Add the modified logic to the above event.

Done.

Finally, I want to say that please never do this in the standard field. This will cause many problems, not just data inconsistency. For example, if you change any one of the Posting Date, Vendor No. or Document No., the financial data will be inaccurate. And since this is changed via AL code, it is difficult to find the cause. So I want to mention it again, please never do it.

PS: Dynamics 365 Business Central: Can we delete Posted Documents (Posted invoices and credit memos)???

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL