Debugging in Aras Innovator

Debugging in Aras Innovator

Debuggers are one of the post powerful tools available to developers. Today we'll be going over how you can use your browser and Visual Studio to debug any method code inside of Aras Innovator.

Debugging a Client Method

JavaScript methods are the simplest to debug. All you need to do is add a single line of code to your method: debugger;. After saving your Method, simply open your browser's developer tools (typically launched by pressing F12 on the keyboard) and perform the action that runs the Method. You should notice that the execution of the Method halts directly where you've placed your debugger; statement.

From here, you can conveniently step through your function line-by-line. Note that I'm using Google Chrome, and your developer tools will look different if you're using another browser.

Checking the Context of a Method

One of the first things I do when I get the question "How do I do X in Aras Innovator?" is open up a debugger. This is especially true if X involves client-side functionality since the information you have access to from a JavaScript method can change significantly based on where the method is called from. The developer tools of our browser can help us figure out what information and functions are available to us.

For example, let's walk through a use case where we want to programmatically download a file. There's a common aras object that's available from almost every client-side method that contains many useful functions for commonly desired use cases. Let's see if this object has anything for downloading a file.

Just by typing in aras.download into the console and checking the autocomplete suggestions, we can see that there are indeed two functions on the aras object for downloading files: aras.downloadFile and aras.downloadItemFiles. By selecting one of these functions and hitting enter, we can even see what the expected arguments are.

So it looks like aras.downloadFile expects a File item and a name to use for the downloaded file. Let's test this by getting a file we already know exists and trying to download it with a different name.

Sure enough, we'll notice that we downloaded our file with the name downloadedFile.txt. Exactly what we were looking for!

This is a simple example, but it covers some powerful aspects of the developer tools that can help you efficiently write JavaScript in Aras Innovator.

Debugging a Server Method

Setting up your environment to debug a server method is slightly more involved. To begin, you'll need to navigate to your Innovator installation which you can find by default at C:\Program Files (x86)\Aras\Innovator\. In this folder, you'll open the InnovatorServerConfig.xml inside of your favorite text editor. Next, add the following tag as a child of the <Innovator/> tag.

<operating_parameter key="DebugServerMethod" value="true"/>

NOTE: Server-side debugging is disabled by default to save disk space. In order to debug server methods, there are temporary files created at `\Innovator\Server\dll\`. We recommend only enabling this option in a Development environment and to only leave it enabled as long as you need to debug your code.

Now that we've configured our Server for debugging, we can add our debugger statements to our server methods. For both VB and C# methods, you'll want to add the following two lines.

System.Diagnostics.Debugger.Launch();
System.Diagnostics.Debugger.Break();

You'll notice when you run your method with these two lines added, you'll be prompted to open the Visual Studio Just-In-Time Debugger.

After saying yes, you'll then be prompted to select which instance of Visual Studio to open the debugger in. If you already have Visual Studio open, you can select that from the list. Otherwise, you can launch a new Visual Studio instance here.

Inside of Visual Studio, you can step through your code line-by-line in much the same way as you did inside of your browser's developer tools.

NOTE: If you did not add the operating_parameter, you will see a message like this when you open Visual Studio, and you will not be able to step through your code.

LOOKING FOR MORE ARAS INSPIRATION?

Subscribe to our blog and follow @ArasLabs on Twitter for more helpful content! You can also find our latest open-source projects and sample code on the Aras Labs GitHub page.