When we post sales order it create an sales invoice but we want when we post sales order it should post the sales order on custom table same as sales invoice in Business central.
I am trying the event subscriber in codeunit the event is onafterpostsalesdoc function but it cannot work. Any other method to post the sales order on custom table please describe this method.
[EventSubscriber(ObjectType::Codeunit, codeunit::"Sales-Post", 'OnAfterPostSalesDoc', '', false, false)]
procedure OnAfterPostSalesDoc(var SalesHeader: Record "Sales Header"; SalesInvHdrNo: Code[20])
var
CustomsalesHeader: Record "MZNNE Sales Header";
SalesLine: Record "MZNNE Sales Line";
Sales_Line: Record "Sales Line";
LineCount: Integer;
i: Integer;
begin
CustomsalesHeader.Init();
CustomsalesHeader.INSERT(true);
end;
You are basically just inserting af blank record in your custom table.
You need to copy the data from the Sales Header record to the record you want to insert in your custom table.
Provided that the field ID's are the same in both tables you can do the following: