Dynamics CRM & Typescript

Roger Hill
3 min readJun 21, 2021

Typescript Development toolchain for Dynamics CRM

Note: I wrote this article a few weeks before Scott Durrow published his excellent series on creating web resources with Typescript. If you’re currently writing web resources in JavaScript you should stop now, and go and watch it here before you continue!

Over the last year I have developed PCF controls for Dynamics CRM using Typescript. After this relative success, I wanted to see if the Typescript development model could be extended to the development of the JavaScript customisations that lie behind the user interface of most significant Dynamics CRM systems. In doing this, I realised that it would be useful to document the reasons for attempting this and the criteria for success.

JavaScript originally appeared some 25 years ago, and was developed as a scripting language for adding a few lines of code to “jazz up” a web page. The name “JavaScript” initially implied that it bore some relation to the Java language that was released by Sun Microsystems a couple of years previously; in reality there is no connection apart from the name and some superficial aspects of the language syntax.

The Java language did have (or quickly developed) the proper underpinnings for the development of enterprise scale projects. In contrast JavaScript has been increasingly used for larger projects, but it has none of the infrastructure that is vital for producing a high quality, enterprise level system.

This has lead to a situation where, over many years, organisations can create libraries of huge JavaScript files, frequently containg several thousand lines of code which are manually deployed from a development environment, and then manually tested.

Predictably this leads to a low quality experience for developers, end users, testers (and project managers!).

Typescript is a language that addresses most of the shortcomings of the JavaScript language, while being fully compatible with all modern browsers (as Typescript is transpiled into JavaScript) and is thus a critical component of attempts to improve the client side toolchain in Dynamics CRM.

Typescript promises to facilitate the development of modular code, using modern OO langage features, that can be type checked at build time, effectively unit tested, then built into a streamlined production deployment file and deployed to CRM in a CD/CI environment.

So what do the success criteria for this look like?

  • Static type checking: avoid the obvious errors of calling Xrm* api calls with the wrong number or type of parameters. Ensure that the internal structure of your programs is validated before it goes anywhere near the client.
  • Unit Testing: write effective unit tests that validate the functionality of your code at some level. Unit tests should fulfill two often contradictary requirements: be robust, but also sensitive to changes that may break the core functionality of your code. They provide a safety net for those who will come after you (and try to maintain what you have written) and ideally will provide some level of insight into the workings of your code.
  • Extensible framework: make it easy to add more functionality to your UI, while being decoupled from existing code that it might otherwise affect.
  • Low friction deployment from the development environment to CRM. Ideally a single command or button click should be sufficient to compile and then deploy your code into the target development system.
  • Continuous Deployment: this means that it will be possible to create a devops pipeline that builds your checked in Typescript code, runs the unit tests than then creates a solution as a deployment artefact that can be used by the release pipeline.
  • Continuous Intergration: we can write a release pipeline that deploys the deployment artefact/solution built from Typescript code to various target systems as required. For proper CI process this would automatically deploy to a test system and run various UI based tests using tools such as EasyRepro to validate the functionality.

I believe that a framework that met all of these requirements would be a huge step forward in the lives of developers, testers, managers and users of Dynamics CRM systems.

--

--

Roger Hill

Working as a Dynamics 365 CRM consultant in London with extensive experience in all aspects of development for Microsoft Dynamics CRM.