I have spent more than a decade working on the many iterations of Microsoft Dynamics 365 and seen it change over the years, but in that time the one thing that has stayed consistent is the need for and use of JavaScript to accomplish front end functionality goals. While powerful, you can run into issues with JavaScript code frequently due to the lack standardization across personnel in an organization and from code samples you find when researching how to solve problems.
What if you could change that? What if you had a particular style you wanted everyone in your organization to start from and get feedback on without other developer’s intervention? The AI tools that are available today are great for this and can be set up easily to give everyone a code generation and review Agent to start with.
Building a Common JavaScript Library for AI-Assisted Development
I started by creating a common library to work with the AI. This library gets deployed to each client’s environment that I work on and houses many of the common Software Development Kit functions for Dynamics 365 (like for setting values on forms or making sections and tabs visible). This library has null checks built into it so you will not have errors if you make mistakes adjusting the code later on and has IntelliSense to help make updates if necessary. A version of our common library as an example can be found here: Common Library.
I have been using Claude, so the set up steps below will be for that, but the steps are similar for ChatGPT. For both Claude and ChatGPT, you will need a pro license. In Claude, go to “Projects”, then “New Project”. Name the project and give a description of what you are trying to do (something about how you are trying to generate JavaScript Libraries for Dynamics 365). Within the project screen, you can add the common library as well as any other previously written libraries you want the project to emulate.
In this case, I have a number of libraries that have a particular namespace structure and use of the common library that I want this to emulate so that all of my example files display those patterns. Finally, I wrote an instruction prompt for what I wanted the project to do. This needed to be very descriptive. For instance, mine includes instructions to leverage the common library as much as possible, to copy the namespace pattern, and to have a particular namespace to default to. With the instructions complete and the files trained on, we can now test the project.
Generating a New JavaScript Library with a Plain-Language Prompt
For this example, I want my project to output a new library for the account table that validates phone numbers. That is plain language and that is the promise of AI, to be able to prompt it with plain language and get a technical output, so let us prompt it with exactly that:


The output shows us that our instructions were followed exactly as we expected. We got the namespace we described in our instructions and the library was coded utilizing functions from the common library as much as was possible. It even describes to us what the expected output should be and how to properly register the event to the form. See below for the entire library:
/// <reference path="nd_CommonLib.js"/> if (typeof ND == 'undefined') { ND = { __namespace: true }; } if (typeof (ND.Account) == "undefined") { ND.Account = { __namespace: true }; } if (typeof (ND.Account.Global) == "undefined") { ND.Account.Global = { __namespace: true }; } if (typeof (ND.Account.Constants) == "undefined") { ND.Account.Constants = { __namespace: true }; } ND.Account.Global = (function () { return { onLoad: onLoad } function onLoad(exCon) { CommonLib.retrieveFormContext(exCon); // Add phone validation on change CommonLib.addOnChange("telephone1", validatePrimaryPhone); } function validatePrimaryPhone() { let phoneNumber = CommonLib.getValue("telephone1"); let phoneControl = CommonLib.getControl("telephone1"); // Clear any existing notifications CommonLib.clearNotification("telephone1", "invalidPhone"); if (phoneNumber) { // Use the RestLib phone validation function let formattedPhone = RestLib.validatePhoneNumber("telephone1"); // If validation was successful and phone was formatted, update the field if (formattedPhone && formattedPhone !== phoneNumber) { CommonLib.setValue("telephone1", formattedPhone); } } } })(); |
How AI Improves JavaScript Quality, Speed, and Standardization
In short, using AI tools like Claude and ChatGPT can allow for quicker, more consistent, and better JavaScript for Microsoft Dynamics 365. Although this was a simple example, I frequently use this tool as a starting point when needing to create or update a JavaScript library, or as a tool to check that I am adhering to standards when I code something for myself. This is a powerful tool that both developers and power users can take advantage of to make their jobs easier, and I hope it will help you in the future too.
Joshua Kranhold - Senior Consultant
Working with New Dynamic
New Dynamic is a Microsoft Solutions Partner focused on the Dynamics 365 Customer Engagement and Power Platforms. Our team of dedicated professionals strives to provide first-class experiences incorporating integrity, teamwork, and a relentless commitment to our client’s success.
Contact Us today to transform your sales productivity and customer buying experiences.