{"title":"AppSourceCop Error AS0118","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/analyzers/appsourcecop-as0118/","by":"JOP-AL","license":"Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/analyzers/appsourcecop-as0118, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/analyzers/appsourcecop-as0118","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"Modifying the length of a field part of the primary key is not allowed.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"AppSourceCop Error AS0118","slug":"appsourcecop-error-as0118","at":0,"chars":2736},{"level":2,"title":"Description","slug":"description","at":89,"chars":87},{"level":2,"title":"Remarks","slug":"remarks","at":176,"chars":342},{"level":2,"title":"How to fix this diagnostic?","slug":"how-to-fix-this-diagnostic","at":518,"chars":78},{"level":2,"title":"Code examples triggering the rule","slug":"code-examples-triggering-the-rule","at":596,"chars":1993},{"level":3,"title":"Example 1 - Decreasing the length of a field, which is part of the primary key","slug":"example-1---decreasing-the-length-of-a-field-which-is-part-of-the-primary-key","at":633,"chars":921},{"level":3,"title":"Example 2 - Increasing the length of a field, which is part of the primary key","slug":"example-2---increasing-the-length-of-a-field-which-is-part-of-the-primary-key","at":1554,"chars":1035},{"level":2,"title":"Related information","slug":"related-information","at":2589,"chars":147}],"text":"# AppSourceCop Error AS0118\nThe length of a field part of the primary key cannot change.\n## Description\nModifying the length of a field part of the primary key is not allowed.\n## Remarks\nThe 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.\nThe validation of the length of table fields part of primary keys was previously done with appsourcecop-as0080 and is now handled by this rule.\n## How to fix this diagnostic?\nReverting the change will fix this diagnostic.\n## Code examples triggering the rule\n### Example 1 - Decreasing the length of a field, which is part of the primary key\nVersion 1.0 of the extension:\n```al\ntable 50100 MyTable\n{\n    fields\n    {\n        field(50100; MyField; Text[50]) { }\n    }\n\n   keys\n   {\n        key(MyKey; MyField) { }\n   }\n}\n```\nVersion 2.0 of the extension:\n```al\ntable 50100 MyTable\n{\n    fields\n    {\n        field(50100; MyField; Text[25]) { }\n    }\n\n   keys\n   {\n        key(MyKey; MyField) { }\n   }\n}\n```\nIn 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.\n> NOTE\n> When no primary key is explicitly defined in the table definition, the first field is used as the primary key.\n### Example 2 - Increasing the length of a field, which is part of the primary key\nVersion 1.0 of the extension:\n```al\ntable 50100 MyTable\n{\n    fields\n    {\n        field(50100; MyField; Text[50]) { }\n    }\n    keys\n    {\n        field(MyKey; MyField) { }\n    }\n}\n```\nVersion 2.0 of the extension:\n```al\ntable 50100 MyTable\n{\n    fields\n    {\n        field(50100; MyField; Text[100]) { }\n    }\n    keys\n    {\n        field(MyKey; MyField) { }\n    }\n}\n```\nIn 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.\nAs 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.\nMoreover, if a dependent extension uses this field, this change of length can lead to runtime exceptions.\n> NOTE\n> When no primary key is explicitly defined in the table definition, the first field is used as primary key.\n## Related information\nAppSourceCop Analyzer<appsourcecop>\nGet Started with AL<../devenv-get-started>\nDeveloping Extensions<../devenv-dev-overview>"}