Effortlessly Manage Pages in Dynamics 365 BC with Codeunit Page Management

Effortlessly Manage Pages in Dynamics 365 BC with Codeunit Page Management

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:

  • Run Item: This action runs successfully even with Page.Run(0, Item) because the Item table has a lookup page ID defined.
  • Run General Journal Line: This action fails using the same logic.

  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.        

  • Run Page Management : The General Journal Line table is used across various templates like Fixed Asset, G/L Journal, Cash Receipts, and Intercompany. Without a specified page ID, an error occurs due to its versatile nature.
  • This is where the Codeunit Page Management comes to the rescue. It simplifies the process by dynamically mapping the appropriate page IDs based on templates.

  • This functionality is not limited to general journals but also extends to sales, purchases, manufacturing, and more.

 // 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)));        

要查看或添加评论,请登录