knowledge(events): qualify StartSession async semantics and fix concurrency-unsafe sample key

Addresses PR #152 review: StartSession is a fire-and-forget background
session (Ok reports only whether it started, not whether the codeunit
succeeded, and errors inside it do not propagate), so the Best Practice
now scopes the recommendation and calls out the durable status/error
channel a synchronous-success write needs. The good sample's
FindLast()+1 entry-number pattern raced under concurrent background
sessions; switched to AutoIncrement, which the platform guarantees is
unique across concurrent transactions.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
waldo1001 2026-09-11 19:40:26 +02:00
parent 4bd52abf98
commit f0bc7c5946
2 changed files with 8 additions and 15 deletions

View file

@ -20,18 +20,9 @@ codeunit 50102 "Transfer Request Create Good"
trigger OnRun()
begin
Rec."Entry No." := NextEntryNo();
// "Entry No." is AutoIncrement, so concurrent background sessions in TargetCompany never race on the same value.
Rec.Insert(true);
end;
local procedure NextEntryNo(): Integer
var
LastRequest: Record "Transfer Request Good";
begin
if LastRequest.FindLast() then
exit(LastRequest."Entry No." + 1);
exit(1);
end;
}
table 50100 "Transfer Request Good"
@ -40,7 +31,7 @@ table 50100 "Transfer Request Good"
fields
{
field(1; "Entry No."; Integer) { }
field(1; "Entry No."; Integer) { AutoIncrement = true; }
field(2; "Item No."; Code[20]) { }
field(3; Quantity; Decimal) { }
field(4; "Location Code"; Code[10]) { }