albxrmtypesgen
v1.0.9-beta3
Published
A TypeScript Declaration Generator for Dynamics 365 Forms
Downloads
17
Maintainers
Readme
XrmTypesGen
A Typescript Type Declaration Generator for Dynamics 365. Inspired by the @types/xrm and XrmDefinitelyTyped.
Usage
Generate your types
Install the npm package:
npm install xrmtypesgen -g
If you wish to install the package locally use the following:
npm install xrmtypesgen --save-dev
and run via npx:
npx xrmtypesgen [options]
Generate the Xrm types:
Username & Password Authentication
xrmtypesgen --url https://myorg.crm11.dynamics.com/ --username [email protected] --password password123 --tenent https://login.windows.net/org.onmicrosoft.com --solution solutionname --output ./types
Client Credential Authentication
xrmtypesgen --url https://myorg.crm11.dynamics.com/ --tenent https://login.windows.net/myorg.onmicrosoft.com --entities "account,contact,lead" --output types --clientid myclientid --secret mysecret
Arguments:
Usage: xrmtypesgen [options]
Options:
-V, --version output the version number
-u, --url <url> D365/Dataverse Url. e.g. https://myorg.crm11.dynamics.com/
-n, --username <username> Username for D365/Dataverse
-p, --password <password> Password for D365/Dataverse
--secret <secret> OAuth Client Secret
-t, --tenent <tenent> Azure Active Directory authority. e.g. https://login.windows.net/myorg.onmicrosoft.com
-c, --clientid <clientid> OAuth Client Id (default: "51f81489-12ee-4a9e-aaae-a2591f45987d")
-s, --solution <solution> Unique D365/Dataverse Solution Name
-e, --entities <entities> Comma seperated list of entities
-o, --output <output> Output path (default: "types")
-h, --help display help for command
e.g. xrmtypesgen --url https://myorg.crm11.dynamics.com/ --username [email protected] --password password123 --tenent https://login.windows.net/myorg.onmicrosoft.com --solution solutionname --output ./types
e.g. xrmtypesgen --url https://myorg.crm11.dynamics.com/ --username [email protected] --password password123 --tenent https://login.windows.net/myorg.onmicrosoft.com --entities account,contact,lead --output ./types
e.g. xrmtypesgen --url https://myorg.crm11.dynamics.com/ --tenent https://login.windows.net/myorg.onmicrosoft.com --entities "account,contact,lead" --output types --clientid myclientid --secret mysecret
Using your types
The generated type declaration depend on @types/xrm
, so lets install them
npm install @types/xrm --save-dev
You are now free to use the new type declaration... Here are some examples.
Form Context:
function myfunc(context: Xrm.Events.EventContext) {
const formContext = context.getFormContext() as Xrm.Ext.Forms.contact.main.Contact.Form;
...
}
Get an attribute, and set the value:
formContext.getAttribute('birthdate').setValue(new Date(1990, 6, 20));
Disable the 'birth date' control within the section called 'PERSONAL INFORMATION', that is within the tab called 'DETAILS_TAB':
formContext.ui.tabs
.get('DETAILS_TAB')
.sections.get('PERSONAL INFORMATION')
.controls.get('birthdate')
.setDisabled(true);
Here's a little video demo...
Why?
Well, I've been using @types/xrm for over 5 years now and XrmDefinitelyTyped for about 2 years. I love the added features XrmDefinitelyTyped provides but dislike the fact that it doesn't extend on @types/xrm given most D365/XRM projects use these types. So I set about creating my own tool to generate type declarations that extend @type/xrm 😁