I like to update "last updated by" field I added on purchase header every time there is a new purchase line added or updated. Therefore, I extended "Purchase Line" table and added the following code for OnInsert and OnModify triggers.
trigger OnInsert()
begin
SetPurchaseHeaderUpdateStatus("Document No.");
end;
trigger OnModify()
begin
SetPurchaseHeaderUpdateStatus("Document No.");
end;
local procedure SetPurchaseHeaderUpdateStatus(purchaseHeaderCode: Code[50])
var
purchaseHeader: Record "Purchase Header";
begin
purchaseHeader.SetRange("No.", purchaseHeaderCode);
purchaseHeader."Last Updated By" := UserId();
purchaseHeader."Last Updated On" := CurrentDateTime();
purchaseHeader.Modify();
end;
I receive the following error.
The purchase header does not exist. Identification field and values: Document Type: 'quote'; No.=''
During debug time I see that "purchaseHeader" is being assigned; code runs fine till I call purcahseHeader.Modify(). It looks like that it might be failing after Modify () method is called. Additionally, I am also wondering why the error message refers to the document type of quote when I am trying to fetch a purchase header.
I really appreciate if someone can help to resolve this issue.