Git Product home page Git Product logo

xrmtypesgen's Introduction

GitHub Workflow Status GitHub Workflow Status npm Coveralls GitHub issues GitHub forks GitHub stars GitHub license GitHub top language Snyk Vulnerabilities for GitHub Repo

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...

demo video

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 ๐Ÿ˜

xrmtypesgen's People

Contributors

oliverflint avatar snyk-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

xrmtypesgen's Issues

[Feature Request] Filter Generated Forms

It would be nice to have an option to read the configuration from file, so that we could add more advanced filters. Like white lists, or black lists for forms or entities. Or specify a list of forms. for example a file XrmTypesGen.config.json like this:

{
  "entities": {
      "account": "Account",
      "contact": ["Contact", "Information"],
      "lead": true
  }
}

Failed to generate with auto generated tab names

When running xrmtypesgen and a form has a tab with an auto generated Guid name it fails with the following error message:

(node:35236) UnhandledPromiseRejectionWarning: SyntaxError: An identifier or keyword cannot immediately follow a numeric literal. (382:79)
  380 |                 * @returns `Xrm.Controls.Tab`.
  381 |                 */
> 382 |                 get(tabname: "{695e07fd-fedf-4e04-ba92-366f59c2c2a2}"): 695e07fdfedf4e04ba92366f59c2c2a2TabControl
      |                                                                               ^
  383 |             }
  384 | 
  385 |             type 695e07fdfedf4e04ba92366f59c2c2a2TabControl = Xrm.Controls.Tab & {
    at e (C:\dev\Test\node_modules\prettier\parser-typescript.js:1:322)
    at Object.parse (C:\dev\Test\node_modules\prettier\parser-typescript.js:1:3072720)
    at Object.parse (C:\dev\Test\node_modules\prettier\index.js:13625:19)
    at coreFormat (C:\dev\Test\node_modules\prettier\index.js:14899:14)
    at format (C:\dev\Test\node_modules\prettier\index.js:15131:14)
    at C:\dev\Test\node_modules\prettier\index.js:57542:12
    at Object.format (C:\dev\Test\node_modules\prettier\index.js:57562:12)
    at Object.render (C:\dev\Test\node_modules\xrmtypesgen\dist\renderer.js:26:34)
    at C:\dev\Test\node_modules\xrmtypesgen\dist\index.js:60:33
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

option name & npm warning

  1. The /tenent switch should be /tenant
  2. Getting a warning during install
    image

*I found this article and wanted to get your thoughts on the claim

The first thing to be aware of is that @types/xrm and XrmDefinitelyTyped are incompatible with each other. You cannot have the DefinitelyTyped type definitions in the same compilation context as the XrmDefinitelyTyped definitions.

https://dyncrmexp.com/2020/06/28/modern-web-resource-workspace-in-dynamics-365-part-2-declaration-files/comment-page-1/

Add support for @types/xrm@v8

There are still a lot of old on premise implementations working with @types/xrm v8, I happen work on a project like this daily ๐Ÿ˜€
It would be nice to support those projects too.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.