XrmToolkit provides both JavaScript and TypeScript files that allow you to have all the intellisense features in Visual Studio for your CRM forms. To learn how to generate these files see the documentation found here.
Both the older JavaScript API (Xrm.Page) and the newer API introduced with D365 9.X are supported. For more information regarding the API's please see Microsoft's documentation here.
When generating the TypeScript intellisense files, each form is placed into a Namespace hierarchy in the following pattern:
Form.{entityName}.{formType}.{formName}.
It is important to understand this as you will need to know the Namespace path of a form before you can use the intellisense for it. For example, if you were to generate the main contact form it would be placed in a Namespace of:
Form.contact.Main.Information
To use the TypeScript intellisense files with the new API's introduced in D365 v9, you need to pass the context during the on-load of the form. For the form in question, make sure to check the box in the Handler Properties to pass the context in this method:
Then define the executionContext parameter something like this:
function OnFormLoad(executionContext: XrmBase.ExecutionContext<Form.contact.Main.Information>) { var firstName = executionContext.getFormContext().getAttribute("firstname").getValue(); }
To use the old 'Xrm.Page' object, declare a const value at the top of the file like this:
declare const Xrm: XrmBase<Form.contact.Main.Information>
Type information for the execution context can be specified using JSDoc notation on the 'OnFormLoad' function as follows:
/** * @param {XrmBase.ExecutionContext<Form.contact.Main.Information>} executionContext execution context */ function OnFormLoad(executionContext) { var firstName = executionContext.getFormContext().getAttribute("firstname").getValue(); }
This tells Visual Studio that the 'executionContext' parameter is of type XrmBase.ExecutionContext<Form.contact.Main.Information> and will provide intellisense for it.
To use the JavaScript file that was generated, simply add a reference to it at the top of the JavaScript file that you want intellisense for:
/// <path="intellisensefiles/contact form - contact - mobile.js" /> var firstName = Xrm.Page.getAttribute("firstname").getValue();