{"title":"CodeCop Warning AA0231","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/analyzers/codecop-aa0231/","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/codecop-aa0231, 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/codecop-aa0231","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":"The data classification context will be lost when using the StrSubstNo method or string concatenation as a parameter in the Error method.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"CodeCop Warning AA0231","slug":"codecop-warning-aa0231","at":0,"chars":1990},{"level":2,"title":"Description","slug":"description","at":113,"chars":249},{"level":2,"title":"Reason for the rule","slug":"reason-for-the-rule","at":362,"chars":446},{"level":2,"title":"Bad code example","slug":"bad-code-example","at":808,"chars":448},{"level":2,"title":"Good code example","slug":"good-code-example","at":1256,"chars":397},{"level":2,"title":"Good and bad practices for fixing the rule","slug":"good-and-bad-practices-for-fixing-the-rule","at":1653,"chars":200},{"level":2,"title":"Related information","slug":"related-information","at":1853,"chars":137}],"text":"# CodeCop Warning AA0231\nStrSubstNo or string concatenation must not be used as a parameter in the Error method.\n## Description\nThe data classification context will be lost when using the StrSubstNo method or string concatenation as a parameter in the Error method. Instead use the ability of the Error method to insert values into the string with placeholders.\n## Reason for the rule\nAll error messages are logged into telemetry and we do not allow adding customer data into telemetry. So, all errors that have a textconst as the first argument actually log the textconst in telemetry, this greatly increases the ability to resolve errors found in telemetry. If StrSubstNo or string concatenation is used as first argument the data classification context is lost and no message text is logged in telemetry.\n## Bad code example\n```al\nvar\n   ErrorMsg: Label 'Customer %1 has incorrect email', Comment = '%1 = Customer No.';\n\nlocal procedure MyProcedure()\nbegin\n    Error(StrSubstNo(ErrorMsg, Customer.\"No.\");\nend;\n```\n```al\nvar\n   Text000Err: Label 'There are no planning lines to make orders for. ';\n   Text007Err: Label 'This template and worksheet are currently active. ';\nlocal procedure MyProcedure()\nbegin\n    Error(Text000Err + Text007Err);\nend;\n```\n## Good code example\n```al\nvar\n    ErrorMsg: Label 'Customer %1 has incorrect email', Comment = '%1 = Customer No.';\nlocal procedure MyProcedure()\nbegin\n    Error(ErrorMsg, Customer.\"No.\");\n\nend;\n```\n```al\nvar\n   ErrorMsg: Label 'There are no planning lines to make orders for. This template and worksheet are currently active. ';\nlocal procedure MyProcedure()\nbegin\n    Error(ErrorMsg);\nend;\n```\n## Good and bad practices for fixing the rule\nUse the ability of the ../methods-auto/dialog/dialog-error-errorinfo-method method to insert values (expressions) into the string that has a placeholder.\n## Related information\nCodeCop Analyzer<codecop>\nGet Started with AL<../devenv-get-started>\nDeveloping Extensions<../devenv-dev-overview>"}