Dynamics 365 Business Central: Ignoring Item variant/reference description for sales/purchase documents (Don’t update Item Description)

Dynamics 365 Business Central

Hi, Readers.
Today I would like to talk about how to ignore Item variant/reference description for sales/purchase documents. This is a question I’ve seen before in the Dynamics 365 Business Central Forum, and I was asked it again recently, so I wanted to discuss it in more detail. More details: Item variant description – ignoring it for sales/purchase documents – Dynamics 365 Business Central Forum Community Forum

As you might know, if you buy or sell items that you and your vendor or customer use different terms for, then you can set up a reference between your terms for the items and the terms that the customer or vendor of that item uses.

This way, the vendor’s or customer’s item description, unit of measure, or variant code is automatically inserted on the relevant documents when you fill in the Item Reference No. field. More details: Use Item References

And Item variants are a great way to keep your list of products under control. For example, you have a large number of items that are almost identical and vary only in color. You can define each variant as a separate item. But you choose to set up one item and specify the various colors as variants of the item. More details: Manage Product Variants

Same as Item Reference, this will also update the item description when you fill in the Variant Code field.

So, what if we want to keep the initial Item Description? Unfortunately, there is no standard setting to control this behavior, it requires customization.

If you don’t want to customize, there is a very simple way, just set the “Description” in “Item Reference” and “Item Variant” to be the same as the Item’s description. This will update to the initial item description.
For example,

And for Item Reference, if you set Description to empty, the system will also keep the initial description, but not Item Variant.
For example,

The empty Description of the Item Variant will also be updated on the line😑.

Next let’s look at the standard code.

Item Reference No.:

table 37 “Sales Line”:

codeunit 5720 “Item Reference Management”:

Variant Code:

table 37 “Sales Line”:

codeunit 5720 “Item Reference Management”:

procedure EnterSalesItemReference(var SalesLine2: Record “Sales Line”):

When it comes to this kind of requirement, there are generally two ways to consider it, skipping the standard modification logic or changing it back after the standard modification. The former has good performance but may skip the needed process, the latter is not as good as the former but is relatively safe.

As an example, this time the modification logic of Item Reference cannot be skipped, so we use the second method. The modification logic of Item variant can be skipped, so we use the first method.

But it is recommended to add a new setting.

Test video:

Great, give it a try!!!😁

Source Code:

codeunit 50118 KeepItemDescription
{
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Item Reference Management", OnBeforeEnterSalesItemReference, '', false, false)]
    local procedure "Item Reference Management_OnBeforeEnterSalesItemReference"(var IsHandled: Boolean);
    var
        SalesSetup: Record "Sales & Receivables Setup";
    begin
        if SalesSetup.Get() then
            if SalesSetup.KeepItemDescription then
                IsHandled := true;
    end;

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Item Reference Management", OnAfterValidateSalesReferenceNo, '', false, false)]
    local procedure "Item Reference Management_OnAfterValidateSalesReferenceNo"(var SalesLine: Record "Sales Line");
    var
        Items: Record Item;
        SalesSetup: Record "Sales & Receivables Setup";
    begin
        if SalesSetup.Get() then
            if SalesSetup.KeepItemDescription then
                if Items.Get(SalesLine."No.") then
                    if Items.Description <> SalesLine.Description then begin
                        SalesLine.Description := Items.Description;
                        SalesLine.Modify(true);
                    end;
    end;
}

tableextension 50111 ZYSalesReceivablesSetupExt extends "Sales & Receivables Setup"
{
    fields
    {
        field(50100; KeepItemDescription; Boolean)
        {
            Caption = 'Keep Item Description';
            DataClassification = CustomerContent;
        }
    }
}

pageextension 50111 ZYSalesReceivablesSetupPExt extends "Sales & Receivables Setup"
{
    layout
    {
        addafter("Allow VAT Difference")
        {
            field(KeepItemDescription; Rec.KeepItemDescription)
            {
                ApplicationArea = All;
                Caption = 'Keep Item Description';
            }
        }
    }
}

PS: Similar steps apply to sales documents and other purchase documents.

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL