Table relation field length mismatch

Properties
PC0028 Warning Design Code Fix Ignore Obsolete

When a field with a TableRelation is shorter than the referenced field, values that fit in the related table may not fit in the source field. A user picks a 15-character customer number from the lookup, but the value is silently truncated to 10 characters before table relation validation runs. The truncated value does not match any record in the Customer table, producing a runtime validation error.

Define the source field with at least the same length as the related field.

Example

table 50100 "Reward Entry"
{
    fields
    {
        field(1; "Customer No."; Code[10]) // Table relation field length mismatch [PC0028]
        {
            TableRelation = Customer."No."; // Customer."No." is Code[20]
        }
    }
}

Set the field length to at least the length of the related field:

table 50100 "Reward Entry"
{
    fields
    {
        field(1; "Customer No."; Code[20])
        {
            TableRelation = Customer."No.";
        }
    }
}

When the diagnostic is reported

  • The source field is a Code or Text field with a TableRelation to a field that has a greater length.
  • When the TableRelation references only a table name (e.g. TableRelation = Customer;), the rule resolves the primary key field and compares its length — provided the primary key consists of a single field.
  • The rule checks fields defined in table extensions as well as base table fields.
  • Conditional table relations (if ... else) are checked for each branch.

See also