Skip to content
Annesofie Nørager edited this page Sep 29, 2021 · 13 revisions

Getting started

Get up and running with XrmDefinitelyTyped in a few minutes by following this guide.

Prerequisities

  • TypeScript >2.0 installed
  • TypeScript is set up to compile .ts files in your project

Step-by-step

Setup:

  1. Install the package via NuGet
  2. Edit the appSettings in the configuration file (XrmDefinitelyTyped.exe.config) to fit your Dynamics CRM environment and needs (see arguments available to XDT). To avoid storing your password in the config file, it is possible to authenticate by using OAuth. This is done, by adding the following arguments in appSettings*:
  <appSettings>
    <add key="url" value="https://<environmentName>.<region>.dynamics.com/XRMServices/2011/Organization.svc "/>
    <add key="ap" value="OnlineFederation"/>
    <add key="method" value="OAuth"/>
    <add key="mfaAppId" value="xxxx" />
    <add key="mfaReturnUrl" value="xxxx"/>
    <add key="username" value="xxxx"/>
  </appSettings>

In doubt about your URL? Check out this documentation

  1. Alternatively, install the NuGet package DAXIF and edit the _Config.fsx file to contain the abovementioned arguments*.

Usage:

  1. Run XrmDefinitelyTyped.exe**. This will generate the desired declaration files at the specified location (or in the current folder if none specified). If you’re using DAXIF; Run the script “CountEntities”.
  2. You will be prompted to put in your credentials, but your password won’t be stored in a file in the solution
  3. Make sure your tsconfig.json file includes the generated typings in the TypeScript context
  4. Create a TypeScript file, or convert your old .js files to .ts
  5. Making form logic? Cast the ExecutionContext.getFormContext object to the form you are coding towards
  6. Start coding!

*: The DAXIF tools contains various scripts for running our different tools as XrmDefinitelyTyped, XrmContext, XrmMockup etc. To read more about DAXIF and how to authenticate using this tool, read [this guide] (https://github.com/delegateas/Daxif/wiki/Using-different-auth-methods) and the additional documentation for DAXIF.

**: Since .exe files can not be run directly from Visual Studio (out-of-the-box at least), script files are included in the package to enable you to run it from the IDE (Powershell: Run.ps1, or F#: Run.fsx).

Creating App registration and Application User:

If you have never made an App Registration you're probably wondering what an "App id" is. We recommend following this guide to create an App Registration in Azure and a corresponding Application User in CDS/Dataverse

Recommended form script file-setup

With the release of Dynamics CRM v9, Xrm.Page has been deprecated. This means that if you are developing towards version 9 or newer, you should use a different file-setup.

Using Dynamics CRM v9 and above

You can get the form context via the execution context on CRM function handlers, and cast it to the desired form type:

namespace DG.Contact {
    var Form: Form.contact.Main.Information;

    export function onLoad(executionContext: Xrm.ExecutionContext<any,any>) {
        Form = <Form.contact.Main.Information> executionContext.getFormContext();
        // Code here..
        Form.getAttribute("firstname");
    }
}

Remember to tick 'Pass execution context as first parameter' in CRM, when adding your function to the form.

Using Dynamics CRM v8 and below

Either make a new variable (i.e. Form), and set it to Xrm.Page casted to the desired form type:

namespace DG.Contact {
    const Form = <Form.contact.Main.Information> Xrm.Page;

    export function onLoad() {
        // Code here..
        Form.getAttribute("firstname");
    }
}

Or declare the Xrm object to be the form your want it to match:

namespace DG.Contact {
    declare var Xrm: Xrm<Form.contact.Main.Information>;

    export function onLoad() {
        // Code here..
        Xrm.Page.getAttribute("firstname");
    }
}

(Older) Video Guide

XrmDefinitelyTyped: Setup, configuration, and usage