Skip to content
Arthur van de Vondervoort edited this page Jul 19, 2024 · 2 revisions

Set NotBlank property to false when 'No. Series' TableRelation exists.

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.

Example

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;
}

image

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.

Journal Templates

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.

Clone this wiki locally