{"title":"System.Clear(var Array of [Any]) Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/system/system-clear-joker-method/","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/methods-auto/system/system-clear-joker-method, 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/methods-auto/system/system-clear-joker-method","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":"Clears the value of a single variable.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"System.Clear(var Array of [Any]) Method","slug":"systemclearvar-array-of-any-method","at":0,"chars":4770},{"level":2,"title":"Syntax","slug":"syntax","at":291,"chars":139},{"level":2,"title":"Parameters","slug":"parameters","at":430,"chars":407},{"level":2,"title":"Remarks","slug":"remarks","at":837,"chars":1204},{"level":2,"title":"Example 1","slug":"example-1","at":2041,"chars":568},{"level":2,"title":"Example 2","slug":"example-2","at":2609,"chars":2027},{"level":2,"title":"Related information","slug":"related-information","at":4636,"chars":134}],"text":"# System.Clear(var Array of [Any]) Method\n> Version: _Available or changed with runtime version 1.0._\nClears the value of a single variable. Also, it clears all the filters that were set if the variable is a record and resets the key to the primary key and the company on a record variable.\n## Syntax\n```al\n System.Clear(var Variable: Array of [Any])\n```\n> NOTE\n> This method can be invoked without specifying the data type name.\n## Parameters\nVariable\nType: ../any/any-data-type\nThe identifier (variable) of any AL data type, including simple and composite data types. The following rules apply when you run the CLEAR method:\n A number variable is set to 0 (zero)\n A string variable is set to empty string\n A date variable is set to 0D (undefined date)\n A time variable is set to 0T (undefined time)\n A Boolean variable is set to FALSE\n## Remarks\nUse the system-clearall-method to clear all internal variables, keys, and filters in the object and in any associated objects such as reports, pages, and codeunits that contain AL code. Note, however, that system-clearall-method does not affect or change values for variables in single instance codeunits.\nFor a composite data type, such as a record or an array, all elements are cleared. Furthermore, all fields in a record will be initialized with the ../../properties/devenv-initvalue-property of the field.\nClear can also be used on the ../guid/guid-data-type. It converts the GUID to zeros. Use the CreateGuid Method \\(Guid\\)<system-createguid-method> to create a new unique GUID.\nClear can also be used to deselect a company. See ../record/record-changecompany-method.\nIf you use Clear on a codeunit, only the reference to the codeunit is deleted and not the codeunit itself, as with Automation objects. This means that the content of the codeunit stays intact.\nIf you have an array of controls, the whole array is destroyed when the array variable goes out of scope.\nIf you have an array of automation servers, you may clear the whole array at once, or clear each element individually.\n## Example 1\nThis example shows how to use the Clear method.\n```al\nvar\n    Text000: Label 'Joe Raybon';\n    Text001: Label 'Initially the variable \"Name\" contains: >;%1\\>';\n    Text002: Label 'After using Clear, the variable \"Name\" contains: >;%1\\>';\nbegin\n    Name := Text000;\n    Message(Text001, Name);\n    Clear(Name);\n    Message(Text002, Name);\nend;\n```\nThe first message window displays the following:\nInitially the variable \"Name\" contains: >;Joe Raybon\\>\nThe second message window displays the following:\nAfter using Clear, the variable \"Name\" contains: >;\\>\n## Example 2\nIn the following example you will declare two variables:\n```al\nvar\n    MyTextVar: Text;\n    GuidVar: Guid;\n```\nThese variables will be declared and cleared, first by using Clear and then by using system-clearall-method.\n```al\nvar\n    Text000: Label 'My Text';\n    Text001: Label 'Initially the variable \"MyTextVar\" contains >;%1> and \"GuidVar\" is defined as >;%2>';\n    Text002: Label 'After using Clear(MyTextVar), the variable \"MyTextVar\" contains >;%1> and \"GuidVar\" is still defined as >;%2>';\n    Text003: Label 'After using Clear(GuidVar) the variable \"GuidVar\" becomes undefined';\n    Text004: Label 'Giving the \"MyTextVar\" variable the initial value again and creating a new \"GuidVar\" results in >;%1> and >;%2>';\n    Text005: Label 'Using ClearAll results in an empty \"MyTextVar\" >;%1> and an undefined \"GuidVar\"';\nbegin\n    MyTextVar : Text000;\n    GuidVar := CreateGuid();\n    Message(Text001,MyTextVar,GuidVar);\n    Clear(MyTextVar);\n    Message(Text002,MyTextVar,GuidVar);\n    Clear(GuidVar);\n    Message(Text003,GuidVar);\n    MyTextVar := Text000;\n    GuidVar := CreateGuid();\n    Message(Text004,MyTextVar,GuidVar);\n    ClearAll;\n    Message(Text005,MyTextVar,GuidVar);\nend;\n```\nThe first message window displays the following:\nInitially the variable \"MyTextVar\" contains: >;My Text\\> and \"GuidVar\" is defined as >;aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb\\>\nThe second message window displays the following:\nAfter using Clear\\(MyTextVar\\), the variable \"MyTextVar\" contains: >;\\> and GuidVar is still defined as >;aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb\\>\nThe third message window displays the following:\nAfter using Clear\\(GuidVar\\) the variable \"GuidVar\" becomes undefined\nThe fourth message window displays the following:\nGiving the \"MyTextVar\" variable the initial value again and creating a new \"GuidVar\" results in >;My Text\\> and >;87654321-4321-4321-4321-BA0987654321\\>\nThe fifth message window displays the following:\nUsing ClearAll results in an empty \"MyTextVar\" >;\\> and an undefined \"GuidVar\"\n## Related information\nsystem-data-type\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}