Dynamics 365 Business Central: How to ignore/hide “Order Date xx/xx/xx is earlier than the work date xx/xx/xx” message in Purchase Order

Dynamics 365 Business Central

Hi, Readers.
Today I would like to briefly talk about a question that has been asked recently, how to ignore/hide “Order Date xx/xx/xx is earlier than the work date xx/xx/xx” message in Purchase Order. This is the message that may pop up when adding new purchase lines or change Order Date.

Order Date 04/03/23 is earlier than the work date 04/10/23.

But here’s an annoying situation, once the order date is earlier than the work date, it pops up once every time you add a line to the page. For example,

Of course, you can temporarily change the Order Date of the purchase header or the Work Date in My Settings, but this is not the best solution.

In fact, we have discussed similar question before, how to ignore messages while validating (Hide Validation Dialog). In it, I shared how to hide the message below.

Shipment Date 03/25/21 is before work date 04/12/21

But unfortunately, it didn’t help him. Because it’s not quite the same this time. However, all the requirements in this type are handled in a similar way, and I will share the investigation and solution to this question again in this post, which will hopefully give you some help.
Let’s see more details.

The first thing you should do when encountering this type of requirement is to check out My Settings -> Change when I receive notifications. If it can be disable, then the customization that is avoided.

This time, neither did it😑.

Then I investigated the standard code and found that this control is in table 39 “Purchase Line”. More details:

Text018: Label ‘%1 %2 is earlier than the work date %3.’;

local procedure ShowEarlyOrderDateMessage()

field(5795; “Order Date”; Date) -> trigger OnValidate()

So, the key point this time is the local procedure ShowEarlyOrderDateMessage().

And, this time there are two easy ways to do it.

The first is the more common way, subscribing to the event before the message. Then just specify ShowMessage as False.

For example,

Source code:

codeunit 50149 MessageHandle
{
    [EventSubscriber(ObjectType::Table, Database::"Purchase Line", OnShowEarlyOrderDateMessageOnAfterCalcShowMessage, '', false, false)]
    local procedure OnShowEarlyOrderDateMessageOnAfterCalcShowMessage(PurchaseLine: Record "Purchase Line"; var ShowMessage: Boolean);
    begin
        ShowMessage := false;
    end;
}

The second way is to use Protected Variables. More details: Dynamics 365 Business Central: Can we access global variables from page extensions or table extensions? Yes, But……

HideValidationDialog is defined as a protected variable, so we can access it in our table extensions.

For example,

Source Code:

tableextension 50112 PurchaseLineExt extends "Purchase Line"
{
    fields
    {
        modify("Order Date")
        {
            trigger OnBeforeValidate()
            begin
                HideValidationDialog := true;
            end;
        }
    }
}

Test Video:

Note: Protected variables are not accessible in Codeunit.

Very simple. Give it a try!!!😁

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL