Skip to main content

Notifications

Business Central forum
Unanswered

Custom page check if Purchase Order exists before advancing

Posted on by 209
Hello!
 
I have a customer that wanted to choose the Purchase Order number themselves when generating a Purchase Order from a Sales Order. I have made the logic that adds the custom Purchase Order number the user inputs, but I need a check in the dialog box.
 
I made a page with a single input:
 
 
When the user writes in their preferred number, I need to check if there is already a Purchase Order existing with that number. If that is the case, the user needs to insert another number. How can I disallow them from advancing from this page if the system finds an existing record?
 
Here is the code to the Page:
 
page 50103 "No Input"
{
    PageType = StandardDialog;
 
    layout
    {
        area(Content)
        {
            field("Purchase Order No."; TempNo)
            {
                ApplicationArea = All;
            }
        }
    }
 
    var
        TempNo: Code[20];
 
    procedure ExitManualNo(): Code[20];
    begin
        exit(TempNo);
    end;
}
 
And this is the code to the codeunit I am using:
 
codeunit 50100 "MyCodeUnit"
{
    SingleInstance = true;
   
    [EventSubscriber(ObjectType::Page, Page::"Sales Order", 'OnBeforeActionEvent', 'CreatePurchaseOrder', false, false)]
    local procedure MyProcedure(var Rec: Record "Sales Header")
    begin
    Clear(InputPage);
        InputPage.LookupMode(true);
        if InputPage.RunModal() = Action::LookupOK then begin
            SalesOrder := Rec;
            UserInputManualNo := InputPage.ExitManualNo();
        end;
    end;
 
    var
        UserInputManualNo: Code[20];
        SalesOrder: Record "Sales Header";
 
        InputPage: page "No Input";
}
 
 
 
 
Categories:

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,451 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,353 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans