Επεξεργασία

Κοινή χρήση μέσω


AppSourceCop Error AS0118

The length of a field part of the primary key cannot change.

Description

Modifying the length of a field part of the primary key is not allowed.

Remarks

The changes validated by this rule aren't allowed because they are destructive changes for the synchronization engine. These changes might also break the runtime of dependent extensions.

The validation of the length of table fields part of primary keys was previously done with AS0080 and is now handled by this rule.

How to fix this diagnostic?

Reverting the change will fix this diagnostic.

Code examples triggering the rule

Example 1 - Decreasing the length of a field, which is part of the primary key

Version 1.0 of the extension:

table 50100 MyTable
{
    fields
    {
        field(50100; MyField; Text[50]) { }
    }

   keys
   {
        key(MyKey; MyField) { }
   }
}

Version 2.0 of the extension:

table 50100 MyTable
{
    fields
    {
        field(50100; MyField; Text[25]) { }
    }

   keys
   {
        key(MyKey; MyField) { }
   }
}

In version 2.0, the type of the field MyField has changed from Text[50] to Text[25]. Because this is a breaking change, if version 1.0 was installed on a tenant, it won't be possible to synchronize and upgrade the version 2.0 of the extension. Moreover, if a dependent extension uses this field, this change of length can lead to runtime exceptions.

Note

When no primary key is explicitly defined in the table definition, the first field is used as the primary key.

Example 2 - Increasing the length of a field, which is part of the primary key

Version 1.0 of the extension:

table 50100 MyTable
{
    fields
    {
        field(50100; MyField; Text[50]) { }
    }
    keys
    {
        field(MyKey; MyField) { }
    }
}

Version 2.0 of the extension:

table 50100 MyTable
{
    fields
    {
        field(50100; MyField; Text[100]) { }
    }
    keys
    {
        field(MyKey; MyField) { }
    }
}

In version 2.0, the type of the field MyField has changed from Text[50] to Text[100]. Even if the length has increased, this change is not supported because MyField is part of the primary key MyKey. As this is a breaking change, if version 1.0 was installed on a tenant, it won't be possible to synchronize and upgrade the version 2.0 of the extension. Moreover, if a dependent extension uses this field, this change of length can lead to runtime exceptions.

Note

When no primary key is explicitly defined in the table definition, the first field is used as primary key.

AppSourceCop Analyzer
Get Started with AL
Developing Extensions