I have a custom field let's say "Package Number" in Sales Header table and also in the "Sales Invoice Header" table. I want the field value to be automatically transferred from "Sales Header" to "Sales Invoice Header" during Posting of Invoice.
Following method works, but I had to add RIMD permission to avoid permission error. My concern is does this mean all users will have RIMD permission? If the user's Permission Sets does not allow "Insert" on Sales Invoice Header, I don't want that person to be able to Post.
I also noticed that removing "Modify();" and "Permissions = RIMD" also saves the fields correctly during Posting. but I am not sure if it will be reliable without "Modify();"
In any case, please advise what is the best way to achieve this. Thank you
Permissions = tabledata "Sales Invoice Header" = RIMD;
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Sales-Post", 'OnAfterSalesInvHeaderInsert', '', false, false)]
local procedure OnAfterSalesInvHeaderInsert(
var SalesInvHeader: Record "Sales Invoice Header";
SalesHeader: Record "Sales Header")
begin
SalesInvHeader."Package Number" := SalesHeader."Package Number";
SalesInvHeader.Modify();
end;