pageextension 80125 salesOrderExt extends "Sales Order"
{
layout
{
}
trigger OnAfterGetCurrRecord()
var
SalesOrderHeader: Record "Sales Header";
SalesOrderAttachmentExist: Boolean;
begin
SalesOrderHeader := Rec;
// Check if the sales order is being posted
if SalesOrderHeader.Status = SalesOrderHeader.Status::Open then begin
// Check if there are any attachments associated with the sales order
SalesOrderAttachmentExist := CheckSalesOrderAttachments(SalesOrderHeader."Document Type", SalesOrderHeader."No.");
// If no attachments exist, display a warning message
if not SalesOrderAttachmentExist then begin
MESSAGE('No attachments have been applied to this sales order. Please attach necessary documents before posting.');
end;
end;
end;
// Function to check if attachments exist for a given sales order
local procedure CheckSalesOrderAttachments(DocumentType: Enum "Sales Document Type"; DocumentNo: Code[20]): Boolean;
var
SalesOrderAttachment: Record "Document Attachment";
begin
// Filter attachments related to the specified sales order
SalesOrderAttachment.SETRANGE("Document Type", DocumentType);
SalesOrderAttachment.SETRANGE("No.", DocumentNo);
// Check if any attachments exist
if SalesOrderAttachment.ISEMPTY then begin
exit(false);
end;
// Attachments found
exit(true);
end;
}