Arsen Aghajanyan
 on Mon Nov 05 2018

Introduction

TypeScript is a typed superset of JavaScript that compiles into JavaScript. TypeScript has several benefits including easier OOP methodology, common errors spotting at compile time, support for new ECMAScript standards, etc.

As a Dynamics 365 Developer, it is quite exciting to use TypeScript within the system. By default, Dynamics don’t support TypeScript. Let’s see how we can sidestep this. In the previous posts, we've seen how to set up the environment, and deploy the code to Dynamics, Now we'll take a look at how we can debug our code within Dynamics 365.

Debugging TypeScript within Dynamics 365

The problem with debugging is that in the Dynamics 365 environment we have only the JavaScript file. We didn’t deploy the TypeScript file so we are not able to access that file via Developer Tools(F12). Let’s see how we can bypass this.

1


We will use Fiddler. Install Fiddler from https://www.telerik.com/download/fiddler. Run Fiddler. Ensure that File > Capture Traffic is checked. If this is turned off, no traffic will be captured.

From the menu select Tools > Options. In the opened window select HTTPS tab and tick Decrypt HTTPS traffic mark. It will prompt to Trust the Fiddler Root certificate. Click Yes to it and each subsequent dialogue. This allows Fiddler to decrypt the HTTPS traffic between the browser and the server so that it can intercept it, log and respond with a different file where needed.

From the menu select Rules > Performance > Disable Caching. This will make sure no caching of files happening and files will be downloaded each time page is refreshed to pick up the latest version.

Go to the Filters and check the Use Filters mark. Check Show only if URL contains mark and write /Webresources/zvt_ in our case. This will specify Fiddler to catch only requests that contain /Webresources/zvt_ in the URL. So, whenever the browser makes a request for our JavaScript resources through the Fiddler we can redirect it down to our local folder and serve that back up to the browser.

2


To do this we use a Fiddler extension called Imposter. Download and Install Imposter from https://github.com/gotdibbs/Imposter.Fiddler. This will add the Imposter tab in the Fiddler.

3


Select Imposter > Profiles > Add New. Enter a meaningful name for Profile Name. In the Base URL field, enter a fragment of the URL that you want Fiddler to keep an eye on to swap files for. In our case, this will be /WebResources/zvt_/. In the Local Directory field, enter the base path on your file system that Fiddler should try to use to look for matching files. Additionally, you can provide some overrides for specific files that won’t match the Base URL. Click Save.

4


From the Imposter menu, navigate to Profiles, then select your profile name, then click Enable.

Note: you can turn on as many profiles as you'd like. This is very comfortable while working with multiple instances.

Clear your browser's cache and navigate to a web resource in Dynamics 365. You should see your local files being served up in the browser.

5


Now you can debug your TypeScript code in Developer Tools(F12) or directly in your IDE. You can make changes in your TypeScript code and test it in the browser without deploying it into Dynamics 365. This is very powerful and can save us a lot of time.

This is the last(at this moment!) part of my blog posts on how to use TypeScript with Dynamics 365. Hope you enjoyed it!

Wish you a Happy Coding!