Effortlessly Manage Pages in Dynamics 365 BC with Codeunit Page Management
Senthil Kumar Varatharajan
Manager – D365 BC Technical Business Central at Mercurius IT| Microsoft Dynamics & SAP Solutions for better business | A safe pair of hands
Managing pages in Dynamics 365 Business Central can sometimes be a hassle, especially when using Page.Run() or Page.RunModal(). A common issue arises when the correct page ID isn't specified, leading to errors.
Page.Run(0, Item);
For instance, using Page.Run(0, RecVar) can cause errors if the lookup page IDs aren't properly set on the table properties.
To illustrate this, I created four different actions:
page.Run(0, GenJournalLine);
Error : You tried to invoke the Page object with the ID 0 from the object Customer List. An object with that ID does not exist in the current application compiled with emit version 24035.
// Gen jnl doesnt specify the lookup page id. but still works based on Page iD from
PageManagement.PageRun(GenJournalLine);
By leveraging the Page Management codeunit, you can ensure the correct pages are called without manually specifying the page IDs, reducing errors and improving efficiency. additionally we can get pageid, pagecaption and weburl
Message('Item Page ID: ' + format(PageManagement.GetDefaultLookupPageIDByVar(Item)));
//ToGet Page Caption
Message('Item Page Caption: ' + PageManagement.GetPageCaption(PageManagement.GetDefaultLookupPageIDByVar(item)));
//ToGet Page WebUrl
RecordRef.Open(Database::Item);
Message('Item Page weburl' + PageManagement.GetWebUrl(RecordRef, PageManagement.GetDefaultLookupPageIDByVar(Item)));