Skip to content
| Marketplace
Sign in
Visual Studio Code>Snippets>Form Scripts for Dynamics 365New to Visual Studio Code? Get it now.
Form Scripts for Dynamics 365

Form Scripts for Dynamics 365

TarekTaamali

| (0) | Free
Set up Dynamics 365 / Power Apps form script projects (autocomplete, lint, format on save), create starter form scripts, and use snippets.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Form Scripts for Dynamics 365

A VS Code extension for writing Dynamics 365 / Power Apps form scripts (JavaScript web resources).

Author: Tarek Taamalli · License: MIT

This is a community extension. It is not made or endorsed by Microsoft. Dynamics 365 and Power Apps are trademarks of Microsoft Corporation.

It does three things:

  1. Sets up a project in one command: autocomplete for the Dynamics 365 client API (Xrm, formContext, executionContext), error checking while you type, Microsoft's Power Apps lint rules, and format on save.
  2. Creates starter form scripts that are namespaced, null-safe and typed for autocomplete.
  3. Adds snippets for the code you write most often (d365...).

Your scripts stay plain .js, so the file you upload to Dynamics needs no build step.


Contents

  • Requirements
  • Install the extension
  • Commands
  • Snippets
  • Settings
  • What the setup creates
  • Day-to-day commands in a project
  • Developing the extension
  • Troubleshooting

Requirements

Tool Why Check
VS Code 1.90 or later Runs the extension code --version
Node.js (LTS) with npm Installs the type definitions and lint tools in each project node --version and npm --version
ESLint extension (by Microsoft) Shows lint warnings in the editor VS Code prompts you to install it after setup

Install the extension

From the Marketplace

In VS Code, open the Extensions panel (Ctrl+Shift+X), search for Form Scripts for Dynamics 365 and click Install. Or run:

code --install-extension TarekTaamali.d365-form-scripts

From the .vsix file (VS Code UI)

  1. Open the Extensions panel (Ctrl+Shift+X).
  2. Click ... (top right of the panel) → Install from VSIX...
  3. Choose d365-form-scripts-0.1.3.vsix.
  4. Reload VS Code: Ctrl+Shift+P → Reload Window.

From the command line

code --install-extension d365-form-scripts-0.1.3.vsix

To check that it is installed:

code --list-extensions | Select-String d365

To uninstall:

code --uninstall-extension TarekTaamali.d365-form-scripts

Commands

Open the Command Palette (Ctrl+Shift+P) and type Dynamics 365, or right-click a folder in the Explorer.

Dynamics 365: Set Up Project

Prepares a folder for form script development:

  1. Writes the setup files (see What the setup creates).
  2. Opens a terminal and runs npm install.
  3. Offers to open the folder if it isn't open yet.

It is safe to run on an existing project:

  • Existing files are never overwritten. They are listed as "kept existing".
  • If a package.json already exists, only the missing packages and scripts are added. Your own entries are not changed.

Which folder is used: the folder you right-clicked, the open folder if only one is open, or a folder you choose when several are open or none is.

Dynamics 365: New Form Script

Creates a starter script for one table:

  1. Asks for the table logical name, for example account or new_projecttask.
  2. Asks for your root namespace, for example your company or publisher name. It is remembered for next time.
  3. Creates <table>.js and opens it.

Example result for account with namespace Contoso:

// Form script for the "account" table.
// In the form editor, add this file as a library and register these handlers
// with "Pass execution context as first parameter" ticked:
//   OnLoad: Contoso.Account.onLoad
//   OnSave: Contoso.Account.onSave
var Contoso = Contoso || {};

Contoso.Account = (function () {
  "use strict";

  /**
   * Returns the field's value, or null when the field is not on the form.
   * @param {Xrm.FormContext} formContext
   * @param {string} name logical name of the field
   */
  function getValue(formContext, name) {
    var attribute = formContext.getAttribute(name);
    return attribute ? attribute.getValue() : null;
  }

  /** @param {Xrm.Events.EventContext} executionContext */
  function onLoad(executionContext) {
    var formContext = executionContext.getFormContext();
  }

  /** @param {Xrm.Events.SaveEventContext} executionContext */
  function onSave(executionContext) {
    var formContext = executionContext.getFormContext();
  }

  return { onLoad: onLoad, onSave: onSave };
})();

Why it is built this way:

  • The namespace (Contoso.Account) avoids clashes with other scripts loaded on the same form.
  • getValue is null-safe, so the script doesn't crash when a field is removed from the form.
  • The @param comments give you autocomplete and error checking on executionContext and formContext.

Register it in Dynamics: in the form editor, go to Form libraries → add the web resource. Then go to Events → On Load → function Contoso.Account.onLoad, and tick Pass execution context as first parameter.

The command refuses to overwrite an existing file and rejects names with spaces or other invalid characters.


Snippets

Type the prefix in any .js file and press Tab or Enter. Press Tab again to move between the placeholders.

Prefix Inserts
d365ns Namespaced form script module with an OnLoad handler
d365onload OnLoad handler with typed executionContext
d365onchange OnChange handler that reads a field null-safely
d365onsave OnSave handler that can cancel the save with a message
d365getvalue Read a field value, null-safe
d365setvalue Set a field value, null-safe
d365lookup Read the id (without braces), name and table of a lookup
d365visible Show or hide a field's control
d365required Set a field to required / recommended / optional
d365notify Show a form banner (INFO / WARNING / ERROR)
d365fieldnotify Show (and later clear) a message under a field
d365retrieve Retrieve one record with Xrm.WebApi.retrieveRecord

Every snippet passes the type check and the lint rules.


Settings

Setting Default Description
d365FormScripts.namespace MyOrg Root namespace used by New Form Script

Change it in File → Preferences → Settings (search for "Dynamics 365"), or in settings.json:

"d365FormScripts.namespace": "Contoso"

What the setup creates

File Purpose
package.json Lists the dev tools: @types/xrm, eslint, @microsoft/eslint-plugin-power-apps, typescript, plus the lint and typecheck scripts
jsconfig.json Turns on autocomplete and error checking for the Xrm API in every .js file, including subfolders
eslint.config.mjs Turns on all Microsoft Power Apps lint rules as warnings (for example, deprecated Xrm.Page usage)
.vscode/settings.json Formats on save and applies lint fixes on save
.vscode/extensions.json Recommends the ESLint extension
node_modules/ Created by npm install. Never upload it to Dynamics.

Tip: you can run the setup once in a parent folder (for example D365-Scripts\) and keep each project in a subfolder. Every subfolder then gets autocomplete and lint with no extra setup. Open the parent folder in VS Code.


Day-to-day commands in a project

Run these in a terminal inside a project folder (Ctrl+` opens one in VS Code).

Command What it does
npm install Installs the tools (the setup command runs it for you)
npm run typecheck Checks every .js file for API mistakes, for example getAtribute instead of getAttribute
npm run lint Runs the Power Apps lint rules on every .js file
npx eslint myfile.js Lints one file
npm update Updates the tools to the newest versions allowed by package.json

npm run typecheck and npm run lint print nothing when everything is fine.


Developing the extension

Project layout

d365-vscode-extension/
├─ extension.js            VS Code commands (prompts, folder picking, terminal)
├─ src/
│  ├─ core.js              File logic: setup, merge package.json, create form script, name checks
│  └─ templates.js         Contents of every generated file
├─ snippets/
│  └─ javascript.json      The d365 snippets
├─ test/
│  └─ core.test.js         Unit tests (node:test)
├─ package.json            Extension manifest: commands, menus, settings, snippets
└─ .vscodeignore           Files left out of the .vsix

To change what gets generated, edit src/templates.js. To add a snippet, edit snippets/javascript.json.

Commands

Run these from the d365-vscode-extension folder:

# 1. Install the packaging tool (once)
npm install

# 2. Run the unit tests
npm test

# 3. Try the extension without installing it:
#    open this folder in VS Code and press F5.
#    A second VS Code window opens with the extension loaded.

# 4. Build the .vsix file
npm run package

# 5. Install (or update) it in your VS Code
code --install-extension d365-form-scripts-0.1.3.vsix --force

Releasing a new version

  1. Raise "version" in package.json (for example 0.1.3 → 0.1.4).
  2. npm test
  3. npm run package builds d365-form-scripts-<version>.vsix.
  4. code --install-extension d365-form-scripts-<version>.vsix --force
  5. Reload VS Code.

Publishing to the Marketplace

Publisher ID: TarekTaamali (managed at https://marketplace.visualstudio.com/manage).

Option A, browser: run npm run package, then on the management page open the publisher → New extension → Visual Studio Code (or Update on an existing one) → upload the .vsix.

Option B, command line: create an Azure DevOps Personal Access Token with scope Marketplace → Manage, then:

npx vsce login TarekTaamali        # paste the token when asked (never save it in a file)
npx vsce publish                   # publish the current version
npx vsce publish patch             # bump the patch version and publish

Sharing with colleagues

Send them the .vsix file and point them to Install the extension. They also need Node.js installed.


Troubleshooting

Problem Fix
No Xrm autocomplete Run npm install in the project, then Ctrl+Shift+P → Reload Window. Check that node_modules/@types/xrm exists.
No lint warnings in the editor Install the ESLint extension (by Microsoft) and reload. npm run lint works without it.
npm is not recognized Install Node.js, then open a new terminal (or restart VS Code) so the PATH is refreshed.
npx tsc prints "This is not the tsc command you are looking for" Use npm run typecheck, which uses the project's TypeScript.
Autocomplete missing in a file outside the project folder Only files inside the folder with jsconfig.json (or its subfolders) are covered.
A setup file wasn't updated Setup never overwrites existing files. Delete the file and run Set Up Project again to get the latest version.

© 2026 Tarek Taamalli. Released under the MIT License (see the LICENSE file).

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
  • Your Privacy Choices
  • Consumer Health Privacy
© 2026 Microsoft