{"title":"OnBeforeOpen (Query) trigger","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/triggers-auto/query/devenv-onbeforeopen-query-trigger/","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/triggers-auto/query/devenv-onbeforeopen-query-trigger, 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/triggers-auto/query/devenv-onbeforeopen-query-trigger","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":"Runs before a query is run and the dataset is generated.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":2,"title":"Syntax","slug":"syntax","at":117,"chars":62},{"level":2,"title":"Remarks","slug":"remarks","at":179,"chars":695},{"level":2,"title":"Example","slug":"example","at":874,"chars":205},{"level":2,"title":"Related information","slug":"related-information","at":1079,"chars":117}],"text":"> Version: _Available or changed with runtime version 1.0._\nRuns before a query is run and the dataset is generated.\n## Syntax\n```al\ntrigger OnBeforeOpen()\nbegin\n    ...\nend;\n```\n## Remarks\nThe AL code of a query object includes the OnBeforeOpen trigger that you can use to change the data that will be included in the resulting dataset. For example, you can use the OnBeforeOpen trigger to apply filters to a column.\nThe OnBeforeOpen trigger only supports local variables; global variables are not supported.\n> NOTE\n> A query cannot be run from the OnBeforeOpen trigger. You cannot call methods from the triggers that run the query, such as ../../methods-auto/query/queryinstance-open-method, ../../methods-auto/query/queryinstance-saveasxml-string-method, ../../methods-auto/query/queryinstance-read-method, or ../../methods-auto/query/queryinstance-close-method methods.\n## Example\nThe following code applies a filter on the Quantity column of the query by calling the SetFilter on the OnBeforeOpen trigger of the query object.\n```al\ncurrQuery.SetFilter(Quantity, '>50');\n```\n## Related information\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}