Posts

Automated Detached Media Cleanup

Image
Introduction In Business Central, there are two ways to store files. Either as Blobs or as Media types. In Media types, we store the files in the database (Tenant Media ID - 2000000184) and then we refer this record in other tables. Whenever there are no records referring a Media, it is deleted from the database. Media types are much more performant as they support caching whereas BLOBs needs to be fetched from the SQL Server every time they are used. Microsoft has moved most of the fields from using Blobs to Media types. However, in scenarios with a high load of writes and deletes, it is possible that there may end up orphaned media records i.e. Media records that are not referenced anywhere. In order to tackle such cases, Microsoft has recently announced the FindOrphans procedure which would return a list of GUIDs of such orphaned Media Types which could then we dealt with as needed. There’s also another tool that has been provided by Microsoft which uses this newly added procedures ...

Reduce Storage Usage Using Data Administration in Business Central

Image
Introduction By default, Business Central comes with 80GB of storage capacity across three sandbox environments and 1 Production Environment with an additional 3GB/Premium License, 2GB/Essential License, 1GB/Device license. These storage limits depending on your business volume may run out if the data is not managed properly. Business Central now comes with a one stop view where you can manage (compress or delete) the entries to reduce storage usage - “Data Administration.” Pre-requisites Business Central Cloud/On Prem References Manage Storage by Deleting Documents or Compressing Data - Business Central | Microsoft Learn Configuration In Business Central, we have had the option to view the capacity usage from the Admin Center for a while now. Recently, they’ve also added a one stop view to check and manage the capacity usage - Data Administration. It can be found directly from the global search. The first time we open this we are greeted with an empty view, the data is loaded after we...

Attach Debugger to an Active Session

Image
Introduction Business Central has recently introduced the functionality to attach a debugger to an active User session. This was previously available in NAV however it has only recently become available for Business Central. Pre-requisites Business Central OnCloud/OnPrem References Attach AL Debugger - MS Docs Configuration To use this functionality, we simply need to create an entry in the launch.json file. The important properties here are the “sessionId” and the “request”. This works much faster than the traditional deploy and debug and really makes your life easier as a developer.   Also, I tried using it for a Production Environment and as expected it didn’t work. Snapshot debugging it is then! Conclusion Thus, we saw how we can attach a debugger to an active user session in Business Central.  Happy Coding!

Master Data Sync Across Companies

Image
Introduction In many business scenarios we have two or more companies which work with the same Customers or Vendors or has same data that is to be shared with multiple legal entities. For such cases, manually making sure everything is in sync becomes difficult as the number of entities increases. For this, Business Central now comes with the functionality to sync master data across multiple companies. This can also be used by consultants for one time syncs if they simply need the setups from one company in another instead of going through the Configuration Package route. Pre-requisites Business Central Cloud/OnPrem References Set up and sync master data across companies Set Up Companies to Synchronize Master Data - Business Central Configuration First, I’ve created two companies in a Sandbox Box which are going to have a uni-directional sync between them. It is possible to have a bi-directional sync however it may cause issues and may cause over-write of data if it isn’t configured pro...

Recurring Sales in Business Central

Image
Introduction In this blog, we’ll be looking at how to reduce manual work in creating Sales Line in Business Central. For this, we’ll be using the Out of the Box feature of “Recurring Sales Lines.” Pre-requisites Business Central OnPrem or Cloud References Standard Recurring Sales - Microsoft Docs Configuration Search for Recurring Sales Lines in Business Central global search and then click on New. Enter a Code for Identification, a short description and the Currency Code, if applicable. In the Lines, enter the Sales Line which are to be re-created. You can also define a Quantity if you want, it can be easily over-written if necessary. Go to the Customer Card for whom the Recurring Sales Line we created is going to be applicable. Then Go to Related > Sales > Recurring Sales Lines. Set the Code of the Recurring Sales Line, we just created and set the Valid From and Valid to Dates. The Insert Rec. Lines have the following options which have the following impact:  Manual - Syst...

Adding Edit in Excel for Custom Listparts

Image
Introduction Business Central provides us an easy method of modifying our data from within Excel using Web Services commonly found in the Edit in Excel action. This can be seen in the commonly used List Pages for example Payment Terms. However this functionality can be missing for certain pages or you might want to have additional logic or filtering before executing this. For this I’ll be demonstrating how to add the “Edit in Excel” action in Business Central pages. Pre-requisites Business Central Cloud References Viewing and Editting in Excel - Microsoft Docs Configuration In the above piece of code, I’ve added the “Edit in Excel” action onto the Blanket Sales Order SubForm to allow for easily adding lines using Excel. Firstly, we define the filters that we will be using on the page that we will be passing in the “EditWorksheetInExcel” procedure of the “OdataUtility” codeunit. Note that these filters are defined as Odata expressions as the “Edit in Excel” functionality uses Excel behi...

Caching in Business Central

Image
References Data Access - Microsoft Docs Select Latest Version - Microsoft Docs Explanation Caching is one of the methods which systems use to improve performance and respond to requests rapidly. In a Business Central system, caching is done at two levels: Business Central Server Instance Data Cache. SQL Server Data Cache. Whenever a User requests data from Business Central, it firsts check whetherThe data is available in the Server Instance’s cache, If not, then it checks the SQL Server Data Cache, And if not here then it fetches the data from the database. The Business Central Server Instance’s Cache is accessible to all the Users connected to that Server Instance. There are two types of cache stored here,Global Cache Private Cache Global cache is the one which is accessible to all the Users connected to the SQL Server. Private cache is only accessible over a transaction, for a particular User, for a particular company. This cache is cleared as soon as the transaction is completed. Wh...

Apply Multiple Entries to Each Other in AL

Image
Introduction While trying to implement a functionality of automatically applying any open invoices for a Customer with the open Payments for the said customer; I observed that there was no quick and easy method to post the application directly. This can be very useful in environments where Payment Entries are created via Integrations without specifying the invoice it needs to be applied to. I read around online but couldn’t find any blogs with the latest method of doing so in Business Central. As such, I spent a good portion of my day debugging the process of applying entries, from start to end as written by Microsoft and to save your time I’m going to jot down my findings here. Pre-requisites Business Central OnPrem/Cloud Configuration Here as an example I’m using a processing report to iterate over all the open Payments in the system and the indented dataitem will iterate over all the open Invoices of the same Customer. The method of iteration and validations may vary however the gen...

Using Postman for Automated Testing

Image
Introduction While using Business Central Web Services or APIs, we often use POSTMAN for testing the request and the responses. Today we’ll see how we can automate this testing to a certain extent using the inbuilt features of POSTMAN. We can have testing logic that runs before every request, after every request or logic that tests on particular request. In the below demonstration, we’ll write automated test to check for GET, PUT, POST and DELETE operations for a single record on a custom API. Postman itself provides a bunch of standard procedures or boiler plate code which we can modify as per our requirements. As this uses Javascript we can also use additional JS features here. Pre-requisites Account in Postman Business Central OnCloud/OnPrem Configuration POST Request So first we are going to be creating a record in the Customer Table with the following fields. One of the common things to be testing with Custom APIs is to verify whether the request is being created successfully (1) ...