Use Database Access Intent List to Boost Performance in Business Central
Introduction For any Business Application, database replication is a necessity for the application to be highly available, fault tolerant and performant without any data throughput issues. Business Central too follows the database replication utilizing a technique known as “Read Scale Out” or “Leader/Follower or Master/Slave Replication Architecture”. Basically, the business operations(Codeunits, Pages, POST/PUT/DELETE API calls) which create the data in the system are relatively quick as compared to Analytical operations (Reports, Queries, GET APIs calls)which read a whole bunch of data from a lot of tables at once. So, in this case, performing both business and analytical operations on the same database can cause performance issues as tables can be locked by an analytical operation while a business operation tries or access or modify that data. A solution for this is using multiple copies of the database in a leader follower architecture.All the write transactions are directed towards the leader database which are then forwarded to the follower databases.All the read transactions can be forwarded to either the leader or the follower database. Please note that this all only happens for Production Environments. Sandbox environments only have the primary database. Side Note If you’re wondering what happens when a User tries to read from a follower database before the leader database was able to send the updated information there (This is called a stale replica). This is an accepted risk when using this architecture. According to CAP Theorem only two of the three properties, Consistency, Availability and Partition Tolerance can be guaranteed. Out of these, partition tolerance has to be tolerated as network failures are inevitable so most systems have to choose between Consistency and Availability. In most cases, RDBMS systems choose Consistency over Availability (as does Business Central) and most NoSQL databases choose Availability over Consistency. Pre-requisites Business Central Cloud/OnPrem References Explanation Setting the property DataAccessIntent to ReadOnly doesn’t guarantee that all the operations that a particular object does are going to be routed via the “replica database”. For example, consider a case where we are using a processing report to update a field on the Item table based on the calculations done using a Query object. Here, when the operation started, given that the processing report intents to update the Item table, the operation was forwarded into the Primary database, now when the Query is executed to fetch the generate the necessary value, the database is still going to be the Primary database. To summarize, the database is not switched in the middle of a transaction. For API Pages where we are only going to be fetching the data from Business Central, we have to set the API page’s Editable property as false and only then we can set the DataAccessIntent to ReadOnly.We don’t have this property for any other page types. For Reports, we can set the DataAccessIntent property directly and if it is a processing report that tries to make any modifications to the data then we end up with a run-time error. For Queries, we can set the DataAccessIntent property directly as well with the same conditions as the Report object but in effect, the only time queries benefit from the “replica database” is if they are used directly as APIs. Almost all the ODATA GET requests are directed to the “replica” database by default in Business Central on Cloud. In the On-Premise Environment, we have a setting “ODataReadonlyGetEnabled” that controls this behaviour. Further, there is a list page in Business Central “Data Access Intent List” which can be used to modify the Data Access List of any Page, Query or Report object. The Default Value indicates that the object should use the pre-defined value defined in AL. The same rules as above are followed when we update the “Data Access Intent” values in the Data Access Intent List page. Conclusion: Thus we saw how Business Central architecture uses the “read scale out” method to ensure consistency and availability and how we can leverage those to boost our application’s performance. Happy Coding!
Share Story :
Using Notifications in Business Central via AL
Introduction Notifications in Business Central are alerts that appears in the Notification bar based on User actions. Notifications stack up from top to bottom, lasting until the user dismisses them, including those from sub-pages. Validation errors are prioritized and shown before other notifications. We can use this to alert the user regarding something without taking all the user’s notification towards it, in the way messages or errors do. They also have the option to allow Users to make a corrective action by embedding the action button directly into the notification. Let’s see how it works. Source Code Pre-requisites Business Central OnPrem/Cloud. References Notification – Business Central Docs Configuration Here, for an example, I’ve created one simple page which takes two inputs. 1. The message that is to be shown in the notification. 2. The message to be shown after the User clicks on the action embedded in the notification. And I have two actions which I’ll be using to show/hide the notification itself. Both of those combined result in a page like below – Now, here is the list of procedures that are available with a “Notification” variable. Let us walk through these one by one. Message – Specifies the content of the notification that appears in the UI. The message function is what we use to decide what the notification will say. I set up a global variable (Message) on my page so the user can type in a value directly, and that value will appear in the message. Scope – Specifies the scope in which the notification appears. According to Microsoft Docs, it is meant to specify the context in which the Notification appears. However for now, we only have the “Local Scope” available as an option so can’t comment much on this. Send – Sends the notification to be displayed by the client. Send is the function used to actually trigger the Notification in the UI. It returns a boolean value indicating whether the notification was triggered successfully or not. Set Data – Sets a data property value for the notification.Get Data – Gets a data property value from the notification.Has Data – Returns a boolean value indicating whether the notification has that value. These three functions work similar to a dictionaries Get, Set or Has functions. As Notifications can be used to perform actions, we need to store some data in them. This data is stored using key value pairs using the “Set Data” function. Then later we can retrieve it back using the “Get Data” function by passing in the specific key. However, if the Key does not exist, we get a run-time error, thus we can use the “Has Data” function to check whether our notification has the specified key. Please note that the data in the Notification is stored till the User dismisses the notification or exits from the page. Add Action – Adds an action on the notification. Here, in the “Show Notification” action, I have added the “Set Data” function to store the data within the global variable “MyData” into the notification with a key as “MyData” as well. Then, we call the “Add Action” function the following parameters In the “Notification Action” codeunit i’ve created a simple procedure which checks, gets and then messages out the value set in the “MyData” key. And so, we get the following output when we click on the action button on the notification. When we click on the action button, the notification automatically disappears. Recall – Recalls a sent notification. However, if we want to manually recall a notification, we can use the “Recall” procedure. After I click the “Hide Notification” button. Id – Gets or Sets the GUID ID for an individual notification. We can use the ID function to Get to Set the ID for a particular notification. We can use this in conjunction with the other functions by passing the ID of one notification and using that to get the data from that notification instead of passing the Notification variable itself. Here I’ve made some changes to the “Show Notification” action such that now it pops up two notifications instead of one and I am storing the ID of the second notification. This is the output. Now, here is the “Hide Notification” action which will be using the ID saved from earlier to recall just the copy notification. And this is the output. Conclusion Thus, we saw how we can use notification to provide non-intrusive alerts to the User along with actions. Happy Coding!
Share Story :
Configure an Azure Connector in LCS
Introduction In this blog, we’ll be looking into configuring the Azure Connector in LCS with the Azure Resource Manager so that LCS can deploy your resources to Azure. Pre-requisites An Azure subscription that you are a co-administrator in. References Configuration Go to Microsoft Dynamics Lifecycle Services and log in with your account. In LCS, when we try to create a cloud hosted environment for the first time, it prompts us to create an Azure Connector first. You can also access this by going to your Project Settings and the “Azure Connectors.” Once, we reach this screen, we have to click on Authorize in the organization where we want to authorize. Please do ensure your account has the necessary permissions for these actions. Once, this is done click on Microsoft Azure Portal as there are a few configurations we need to do in the Azure Portal. Click on Subscriptions. From the Subscriptions list, we can note down the Subscription ID as we will need it while creating the Azure Connector. The “Subscription ID” is also available in the Overview section of the Subscription. Then go to the Access Control (IAM) tab and click on Add and then Add Role Assignment. Then go to Role -> Privileged Administrator Roles and then search for “Contributor”. Click on it and then click on Next. In the members tab, click on User, group or Service Principal and click on Select Members. After that search for and add “Dynamics Deployment Services [wsfed-enabled]” and your own user to this role assignment. Once that is done, we’ll get a confirmation message. After that, we can move back to the LCS for configuring the Azure Connector. We click on Add to create a new Azure Connector and get the following pop-up. Here we add a name for the connector, Azure Subscription ID and the Domain Name. Name can be anything that you want, the Domain Name in most cases is the part of your email address after the @. For e.g. it’d be “microsoft.com” in case of rbansode@microsoft.com. For the Azure Subscription ID, we have already stored that from the previous steps. Once we add the necessary values and click on next we get the following pop-up. We’ve already completed the necessary steps in the Azure Portal so we can simply click on Next. After that, we get the following pop-up. We’ve completed the steps mentioned in the Ensure you are a subscription user section. If for some reason you are facing any difficulties in that you can also try the steps from the Apply a Subscription Tag section. Apply a subscription tag When you click on Get a Code you’ll get the following pop-up which includes a unique verification code. We copy this and head on to the Azure Portal. Then go to your subscription in Azure Portal. Head to the Tags section and create a new entry with name as “LifecycleServicesAuthCode” and the value as unique verification code from LCS. If neither of those methods work, there is a soon to be deprecated method mentioned as well where you upload the certificate downloaded from LCS into the “Management Certificates” of your Azure Subscription. Hopefully, one of these three methods work out for you and you’ll get the following pop-up. Once you click on connect you’ll see an entry created in your Azure Connectors. This indicates that your Azure Account has been linked and now LCS can utilize it to create resources in Azure on your behalf. Side Note If you see the following error message then that means there was an error with one of the three suggested approaches you choose. You can try with another approach and start over. Conclusion Thus, we saw how to configure the Azure Connector in LCS. Happy Coding!
Share Story :
Create a New Environment in LCS for D365 Finance and Operations
Introduction In this blog, we’ll be looking into creating a new environment for D365 Finance and Operations or D365 Commerce. Pre-requisites References Configuration Go to Microsoft Dynamics Lifecycle Services and log in with your account. If you select D365 Commerce, you get the following screen. If you select D365 Finance and Operations, you get another screen where you have to specify whether the project is an actual implementation or just for evaluation after which you get the same screen as below. Once the Project is created, we get the following screen. From here, we click on the hamburger menu at the top and then click on Cloud Hosted Environments. Click on Add to create a new environment. If you get the below pop-up asking to configure an Azure Connector, please refer to my blog – “Configure an Azure Connector in LCS”. Once, you have an Azure Connector configured, you can click on Add again and get the following pop-up. After selecting the Application and Platform version, you’ll get the option to select the environment topology. DEMO – A demo environment includes only Microsoft demo data. You can use a demo environment to explore default features and functionality. DEVTEST – A DevTest environment is for development or build. You can use this environment for development or build. Then we get another pop-up to select the environment topology. After that is selected, we decide the environment name and the size of the VM that is to be used for this environment. You can read more about VM sizes here – VM sizes – Azure Virtual Machines | Microsoft Learn Once we click on Next we get the last pop-up after which the environment gets deployed. Once we click on deploy, it takes about 6-8 hours to deploy the environment after which it’ll be available in the cloud-hosted environments section. If, for some reason, you try to create an environment with the latest platform and application version and that deployment fails, you can try to create an environment one platform/application version below that. Conclusion Thus we saw how to create an environment in LCS for either D365 Finance and Operations. Happy Coding!
Share Story :
Master Data Sync across Companies in Business Central
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 Microsoft Dynamics 365 Business Central (Cloud/OnPrem) References Set up and sync master data across companies | Microsoft Learn Set Up Companies to Synchronize Master Data – Business Central | Microsoft Learn 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 properly. Here we can specify which company the data is going to be pulled from and whether we want to enable the synchronization or not. So, I’ll select “CRONUS USA Inc.” as the Source Company and then I’ll click on the “Synchronization Tables” action to show the list of the tables that I want to synchronize. Here by default, all the tables are enabled, I’ve disabled most of them and only selected a few.You can add your custom tables as well. Further, there’s also the option to add filters so if we only want data that fulfils a certain criterion to be pulled into this company that can be managed from here. An example of this would be, a Parent company which has Customers globally which has a local company in a particular country and only wants customers from the said. Further, we can also specify which exact fields we want to sync and whether we want to over-write the data if, there is any present in the current company, during the sync. After that, we go to the “Master Data Initial Sync.” action on the “Master Data Management Setup” and we see the list of the tables that are to be synced along with the “Sync. Mode”. We can change the Sync modes using the action at the top (“Use Full Sync” or “Use Match Based Coupling”) In either case, if we want the data in the Parent Company to over-ride the data in the child company, we have to set the “Overwrite Local Change” field either at the field level or the table level. If it is set to false, then the change fails, and we can see the same in the Synchronization Log. Once this is done, we can click on “Start All” which will start the synchronization process. It is only meant to be run once, as after this the synchronization jobs will take over. Once, everything is done syncing, we get the results as well. After this, as long as the “Enable Synchronization” is set to true on the “Master Data Management Setup” the jobs will keep the data in sync between the two companies. As an example, I’ve created a customer in the parent company and the same gets created into the child company directly within a few seconds. Conclusion Thus, we saw how we can use the native functionality of Business Central to sync data across companies. Happy Coding!
Share Story :
Attach a debugger to an Active User Session in Business Central
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 Cloud/OnPrem References https://learn.microsoft.com/en-us/dynamics365/release-plan/2023wave1/smb/dynamics365-business-central/attach-al-debugger-active-session-or-next-session-specific-user Configuration To use this functionality, we simply need to create an entry in the launch.json file. 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!
Share Story :
Creating Sales Order/Sales Quote from POS in LS Central
Introduction LS Central allows us to create a Sales Order or Sales Quote directly from POS. I will be demonstrating the same below in this blog. Pre-requisites LS Central v16+ Business Central OnPrem/OnCloud References Suspend Type, Sales Type (lsretail.com) Configuration Search for “Sales Type” in Business Central Create a new record titled “SALES ORDER” in it. Make sure to set the Suspend Type to Sales Order/Sales Quote as required. I am setting it to Sales Order for this example. Log In to your POS with a POS Super User account and Right click on a button and go to button properties, I’m using the default “SUSPEND” button for example here. Set the command to “SUSPEND” and the parameter to the “Sales Order” record you created a few moments ago. Once this is done, create a new Transaction with a Customer and then click on the button. In the confirmation box, click on Yes. If you check in Business Central now, you can see that a new Sales Order has been created. You can also see the same from POS itself if you click on the “Sales Order” button that we created just now. Conclusion: Thus we saw how to create a Sales Order/Sales Quote directly from POS. Happy Coding!
Share Story :
Working with OData Bound Actions
Introduction OData Bound Actions allows us to perform logic in Business Central by hitting specific end points. We can also pass in parameters and get results in response. It’s very similar to using Azure Functions but is natively built into Business Central at no extra cost! In this example, we’ll be returns the Base64 version of an Image of a Customer, we will also see how to get the Image for any other customer as well. Pre-requisites Business Central OnCloud/OnPrem References WebServiceActionContext Data Type – Business Central | Microsoft Docs Creating and Interacting with an OData V4 Bound Action – Business Central | Microsoft Docs Configuration OData Bound Actions are written on Pages or API – Pages that you are declaring as Web Services. In this example below, I’ve created a simple Customer Page with a few fields and kept the OData key field as the “No.” field. I’ve also defined this as a Web Service in Business Central. To create a OData Bound Action, we create a Global Procedure with the Service Enabled decorator. In this procedure, we have to create a WebServiceActionContext variable and set the “ObjectType”, “ObjectID” and Keys that we are using for this Web Service, which is “No.” in this case, after our processing is done we also need to set the “Result Code” for this request. In the above piece of code, I’ve written simple logic which converts the content of a Media Data Type (Image field) to Base64 Text and returns it. In Post-Man if you check of the metadata, you’ll be able to see this action defined in the metadata. Now, it’s time to test out OData Bound Action! To call the OData Bound Action, we need to be working with a single record. So we specify the “No.” field to identify a single record. Now, we append our procedure name as “NAV.[Procedure Name]” and make a POST request. If we put this Base64 through a Base64 to File Converter, we can see that the original data is recovered. Now, we create a new procedure, which will take the System ID as a parameter and return the Image data for that Customer Record. If you want to pass the parameters to the OData Bound Actions, you have to do it as the Body of the Request. Conclusion: P.S. I’ve tried but it seems polymorphism doesn’t work with this. I hope this was insightful and a quick start on how to write OData Bound Actions. Happy coding!
Share Story :
Sending Email in Business Central without SMTP Mail
Introduction With SMTP Mail being deprecated, Business Central now provides us with a new and enhanced way for writing custom logic to send emails. To use this new functionality you have to first configure Email Accounts in Business Central, which you can find here. Pre-requisites Business Central onCloud References Developing with the new enhanced email feature | Dan Kinsella Configuration The new method uses the Email Message (ID: 8904) and Email (ID: 8901) Codeunits. I’ve added multiple actions below and I’ll be describing what the expected behaviour is. This is the simple piece of code which sends an email with the specified Recipients, CCs and BCCs.We can specify multiple recipients and dynamically as the lists are not bound by size. We can also call a simpler version of this method, where we don’t need to specify the CC and BCC. Changing the “OpenInEditor” procedure of “Email” codeunit causes a page to be opened up where you can edit the message before you send it. You can also add attachments or you can save the message draft. Changing the “OpenInEditorModally” procedure of “Email” codeunit causes a page to be opened up (as “RunModal”) where you can edit the message before you send it. You can also add attachments or you can save the message draft. “SaveAsDraft” procedure saves the email as a draft and you can view it in the “Email Outbox” where you can make any changes if necessary and send it directly from there. You can also add attachments to the email directly from code. Conclusion Thus we saw how we can send emails in Business Central v20.
Share Story :
Blocking Items in LS Central from POS
Introduction LS Central has its own unique way of preventing Items from being sold which is different from the standard “Blocked” option field we get on the Item Card. It also comes with detailed and refined permissions which can fit most business needs. All of this is done using another related table known as “Item Status.” Pre-requisites: Business Central OnCloud/OnPrem LS Central v16 References: Item Status (lsretail.com) How to Block Items From Sale at the POS (navisiontech.com) Configuration Open the Item Card for the Item you want to block. Open the “Item Status” for that Item. Click on the “Status Code” and Click on “Select from full list.” Create a new record with code “BLOCKED” and enable all the fields. Here, you can see all the detailed controls available. Conclusion: Thus, we saw how we can Block Items on POS in LS Central and other finer controls available at our disposal in LS Central.
