-
Notifications
You must be signed in to change notification settings - Fork 33
LC0067
Arthur van de Vondervoort edited this page Jul 19, 2024
·
2 revisions
When the 'No. Series' TableRelation is present on the table, assigning the primary key might occur after inserting the record, which could cause an error due to the NotBlank property set to true.
table 50100 MyTable
{
fields
{
field(1; "No."; Code[20]) // The NotBlank property should be set to false (or removed) if a TableRelation of 'No. Series' is present on the table.
{
NotBlank = true;
}
field(2; Description; Text[100]) { }
field(3; Type; Enum MyType) { }
field(4; "No. Series"; Code[20])
{
TableRelation = "No. Series";
}
}
keys
{
key(PK; "No.")
{
Clustered = true;
}
}
trigger OnInsert()
var
NoSeries: Codeunit "No. Series";
begin
Rec."No." := NoSeries.GetNextNo('MyNumberSeriesFromSetup');
end;
}
In this example an error will occur when creating a new record, where the NotBlank
property is checked earlier on then the OnInsert
-trigger is executed.
field(1; Name; Code[10])
{
Caption = 'Name';
NotBlank = true;
}
...
field(16; "No. Series"; Code[20])
{
Caption = 'No. Series';
TableRelation = "No. Series";
trigger OnValidate()
begin
if "No. Series" <> '' then begin
if Recurring then
Error(
Text000,
FieldCaption("Posting No. Series"));
if "No. Series" = "Posting No. Series" then
"Posting No. Series" := '';
end;
end;
}
There is an exception to this rule, for (custom) Journal Template tables, where the combination of NotBlank = true
is desirable, where also a table relation to the "No. Series" table is present. The rule will not be raised if the Primary Key field is named Name
.