Today I’m going to show you how to debug your Acumatica code using the Visual Studio Debugger. It’s a rather simple task really and rather important part of the development process. The exciting news here is that because we have integrated so well with the Microsoft Visual Studio IDE, developers can move back and forth effortlessly between Acumatica and the IDE, including debugging and stepping through integrated application code. In this post, I thought it might be of some utility to see just how easy the process actually is for you or your developers to do.
Let’s take a simple validation code example to illustrate the process. We have an Acumatica form with a custom field we have created that we wish to test some simple field validation. For our purposes, a valid entry is alpha-numeric and shouldn’t contain any extraneous characters. Therefore, #, $, %, ^, &, etc. are not acceptable for this particular field.
Here’s the C# code for validating this constraint to the field:
In the Acumatica Journal Entry Form, we have created a custom field (Truck ID), highlighted in dark-red below in fig. 2, which identifies each of our food trucks in the field in order to link sales for each truck.
You might have noticed from the screen-shot above that we have customized the entire form’s “theme” and white labeled our Acumatica application for our fictitious demo company “Frank’s Food Truck”. We’ll discuss how we did this in a future post. In an upcoming Acumatica Webinar, which we are producing on September 22nd, we’ll demonstrate this more fully. Oh, and by the way, you can conveniently register for the webinar, here… should wish to see a live demo on how to integrate and white label your business applications. <End of shameless plug>
To get started, we have our Acumatica application opened, and now we open up Visual Studio and simply Run as Administrator by right-clicking on Visual Studio and then select FileOpen Website… In our example, we have the Website named Acumatica6Demo running locally.
When the website is loaded, you will have a view similar to the one below in Fig. 4.
Once we have the website loaded, we can find the code under the App_RuntimeCode folder. In our example, our little code snippet is in the C# JournalEntry.cs file. By selecting this .cs file, we see the code above. We can set a breakpoint by selecting the separator column to the left of the line number we wish to begin or using the F5 key. At this point, we can start the debugger and step through our code. We do this by selecting Debug from the menu in Visual Studio and then by selecting Attach to Process… or using the key combination Ctrl+Alt+P. Now the following dialog appears (Fig. 6) below.
But before we do anything further, we should check and make sure our Compilation Debug setting is set to “true” in our web.config file. Open the file in the Solution Explorer, which you can find at the bottom of the drop down list of files – open the file and then do a “quick search” by pressing the keys Ctrl-F and typing “compilation”. You should go right to the line you need and then make sure the setting Compilation Debug is set to “true”. See the Fig. 5 below – look for the dark-red boxes which highlight the areas of which I’m speaking.
Now that you validated that you have the setting necessary to debug your Acumatica Code, you can go ahead and set your breakpoint(s) and attach to the correct process running that we need for debugging the application. Simply press “w” and you will go near or right to the file we need to attach: w3wp.exe. Select this file and press the Attach button and we are off and debugging.
We can now set our breakpoint(s) and start stepping through our code and correct any problems we might have or just see how own code flows through the application when validating the field.
So let’s review…
First, we open our Acumatica application and navigate to the form where we have customized and integrated our code.
Second, we open our website inside of Visual Studio – but remembering to open Visual Studio in administrator mode (Run as Administrator), where the Acumatica application instance is running.
Third, we open the web.config file to make sure our Compilation Debug setting is set to “True”.
Forth, we open the .cs file under the App.RuntimeCode folder. In our example, the file is called JournalEntry.cs. We navigate to the code we want and set our breakpoint.
And lastly, we attach to the ws3wp.exe process and then we can step through our code. Pretty simple but very powerful integration.
Our promise to you:
1. We will never give your e-mail address to anyone else for any reason.
2. You can opt-out at any time.
Signing up for newsletters indicates you agree with our terms of service
If you decide that you no longer want to receive a newsletter, you can unsubscribe by clicking the "Unsubscribe" link, located at the bottom of each newsletter.