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";
}