{"title":"OnAfterLookup (Page Field) trigger","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/triggers-auto/pagefield/devenv-onafterlookup-pagefield-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/pagefield/devenv-onafterlookup-pagefield-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/pagefield/devenv-onafterlookup-pagefield-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 after a lookup is activated passing the selected record as a RecordRef.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"OnAfterLookup (Page Field) trigger","slug":"onafterlookup-page-field-trigger","at":0,"chars":2794},{"level":2,"title":"Syntax","slug":"syntax","at":174,"chars":182},{"level":3,"title":"Parameters","slug":"parameters","at":256,"chars":100},{"level":2,"title":"Remarks","slug":"remarks","at":356,"chars":487},{"level":2,"title":"Example","slug":"example","at":843,"chars":1834},{"level":2,"title":"Related information","slug":"related-information","at":2677,"chars":117}],"text":"# OnAfterLookup (Page Field) trigger\n> Version: _Available or changed with runtime version 7.0._\nRuns after a lookup is activated passing the selected record as a RecordRef.\n## Syntax\n```al\ntrigger OnAfterLookup(Selected: RecordRef)\nbegin\n    ...\nend;\n```\n### Parameters\nSelected\nType: ../../methods-auto/recordref/recordref-data-type\nThe selected record.\n## Remarks\nThis trigger is introduced with runtime 7.0 of AL to address issues that arise when in Business Central, for example, more items have the same Description. With former solutions, the lookup mechanism would find the selected record based on the filtering in the lookup dialog. This made it impossible to predict which record the user had selected.\n> NOTE\n> If you have defined an devenv-onlookup-pagefield-trigger, the devenv-onafterlookup-pagefield-trigger will not be fired.\n## Example\nThe following is a simplified example of how the OnAfterLookup trigger can be used. The No. and Description fields point to fields in the Item table and should be updated at the same time, even if only one of the fields is available in a dropdown; the corresponding field must also be set. No. is the primary key and unique, but there could be more records in the Item table with the same Description. The OnAfterLookup trigger looks up the chosen record and returns it in a RecordRef.\n```al\n\ntable 37 \"Sales Line\"\n{\n    // Skipped\n\n    fields\n    {\n        // Skipped\n\n        field(6; \"No.\"; Code[20])\n        {\n            TableRelation = Item;\n        }\n        field(11; Description; Text[100])\n        {\n            TableRelation = Item.Description;\n            ValidateTableRelation = false;\n        }\n\n        // Skipped\n    }\n}\n\npage 46 \"Sales Order Subform\"\n{\n    SourceTable = \"Sales Line\";\n\n    layout\n    {\n        area(content)\n        {\n            repeater(Control1)\n            {\n                // Skipped\n\n                field(\"No.\"; \"No.\")\n                {\n                    trigger OnAfterLookup(Selected: RecordRef)\n                    var\n                        Item: record Item;\n                    begin\n                        Selected.SetTable(Item);\n                        Validate(Description, Item.Description);\n                    end;\n                }\n                field(Description; Description)\n                {\n\n                    trigger OnAfterLookup(Selected: RecordRef)\n                    var\n                        Item: record Item;\n                    begin\n                        Selected.SetTable(Item);\n                        Validate(\"No.\", Item.\"No.\");\n                    end;\n                }\n                // Skipped\n            }\n        }\n    }\n}\n```\n## Related information\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}