I have narrowed it down.
If I have Recurring Purchase Lines set on Automatic for this vendor/document type, I get the error.
Other vendors without recurring purchase lines are fine.
If I change the type to Manual or Always Ask then it's fine but then it's a manual process that I would like to avoid.
This was 100% fine in 2023 Wave 1 and before, without and without my customisations. Removing custom apps in Sandbox doesn't make a difference with 2023 Wave 2.
Debugging got me to this section of Table 38 Purchase Header:
trigger OnInsert()
var
IsHandled: Boolean;
begin
OnBeforeOnInsert(Rec, IsHandled);
if IsHandled then
exit;
InitInsert();
if GetFilter("Buy-from Vendor No.") <> '' then
if GetRangeMin("Buy-from Vendor No.") = GetRangeMax("Buy-from Vendor No.") then
Validate("Buy-from Vendor No.", GetRangeMin("Buy-from Vendor No."));
if "Purchaser Code" = '' then
SetDefaultPurchaser();
if "Buy-from Vendor No." <> '' then
StandardCodesMgtGlobal.CheckCreatePurchRecurringLines(Rec); <---- THIS LINE IS HIGHLIGHTED IN THE DEBUGGER
end;
Not that that gets much much closer to fixing it, but I'm 99.9% sure it's an issue with automatic recurring purchase lines. I shall continue to dig, and will update this is I solve it in case other people have the same issue.
Edit: I have compared the code between V22.5 and V23.0 in the codeunit Standard Codes Mgt..dal and they are the same other than the addition of namespaces and using at the top. Every line thereafter is identical. So I'm either going to have to go deeper, or I'm already on the the wrong track and will just get lost!