@aappddeevv/dynamics-client 中文文档教程

发布于 7年前 浏览 22 项目主页 更新于 3年前

dynamicscli - 用于处理在线 Microsoft Dynamics 应用程序的 nodejs CLI 应用程序和客户端框架。 该应用程序目前不会使用本地系统进行身份验证(或者至少我不这么认为)。

dynamicscli 使用 ODatav4 REST 数据 api,这意味着您必须向 Azure Active Directory 注册应用程序以允许 CLI 连接到服务器。 注册很容易,但您需要管理员权限才能创建注册。 您可以使用任何允许您的用户 ID 访问数据并具有应用程序 ID 的应用程序注册。

dynamics-client 两个特性:

  • A CLI that can be used from any OS. While one could use PowerShell for everything, its much easier to add commands or make commands robust using an application directly.
  • An extensive client library that is performant on the nodejs platform. You can use this as a framework for developing small Dynamics applications like ETL or platform management. For example, I added a command to help manage the dynamics platform in around 30 minutes and it worked the first time.

dynamicscli 是用 scala.js 编写的,这是一种小型语言,具有更广泛的类型安全性、不变性和更高的一致性。 它是编写逻辑和效果繁重代码的好语言。

为什么是节点? nodejs 拥有大量面向 Web 的资源,内存轻量级,同时仍然足够快。 您还可以直接使用 CRM Web 应用程序的客户端框架。 您还可以将其用于与 CRM 无缝集成的热重载本地开发,从而轻松开发新的 CRM UI 扩展。 在 azure 上运行一个 nodejs 实例也意味着你可以将 dynamicscli 部署到 azure 并且有一个持续运行的 Dynamics platform 处理平台准备就绪。

dynamicscli 自动处理来自动态的多页结果的分页以及自动重试。

Installing

目前,您需要从 github 构建解决方案。 我们将很快在 npm 上发布 CLI 程序。

npm i -g dynamics-client

Running

脚本可以运行,假设在路径上:

dynamicscli --help

如果需要直接用node运行,

node /path/to/dynamicscli <args for dynamicscli>

CRM Connection Parameters

Dynamics连接参数应该放在json文件中。 默认为 crm.json。 该文件应如下所示。 还显示了一些典型值,但您必须找到与您的应用相匹配的值。

{
    "tenant" : "<yourorgname>.onmicrosoft.com",
    "authorityHostUrl" : "https://login.windows.net",
    "username" : "<userid>@<tenant>",
    "password" : "<yourpassword>",
    "applicationId" : "<appid>",
    "dataUrl": "https://<yourorgname>.api.crm.dynamics.com/api/data/v8.2/",
    "acquireTokenResource": "https://<yourorg>.crm.dynamics.com"
}

你的密码也可以在环境变量 DYNAMICS_PASSWORD 中,因为你应该避免在可能被签入版本控制的配置文件中使用密码。

上面显示的域名是 .onmicrosoft.com 但域名不同,它可能是 mycompany.comdataUrl 可以从 CRM 应用程序设置区域中的开发者页面获取。 applicationId 只能从我们的 Azure Active Directory 应用程序的注册页面获取。 有时,applicationId 称为 clientId。 authorityHostUrl 只有在您知道应该更改它时才应更改,否则,请将其保留为与上面的值相同。

如果省略,可以推断出一些信息。 例如,tenant 可以从 username 推断出来,dataUrl 可以从 acquireTokenResource 推断出来,但最好直接指定它们。

创建连接文件后,将其与 -c 选项一起使用。 如果您连接到多个组织,只需在组织之后命名连接文件,例如 myorg1.json 或 myorg2.json,然后使用它 -c myorg1.json。 或者,在 DYNAMICS_CRMCONFIG 中指定配置文件并跳过在命令行上提供选项。

如果您通过 GraphClient 使用 Graph,请使用以下参数:

{
 ...
 "authorityHostUrl" : "https://login.microsoftonline.com",
 "dataUrl": "https://graph.microsoft.com/v1.0",
 "acquireTokenResource": "https://graph.microsoft.com",
  ...
}

您还可以使用 https://outlook.office.com 直接在 https://outlook 访问 outlook API。 office.com/api/v2.0 为数据 url。

Commands

一般的 CLI 用法是 dynamics command [subcommand] [opts]

使用 dynamics --help 打印帮助并查看命令。

What can you do?

您可以使用 CLI 执行的一些操作包括:

  • List and manage:
  • Publishers
  • Solutions
  • System jobs
  • Import maps
  • Execute actions (bound and unbound)
  • plugins (one-time or watch) update an assembly (.dll) that is already registered.
  • Option sets
  • Processes - Workflows
    • List/activate/deactivate/run (against a query)
  • SDK Messages
    • List/activate/deactivate
  • Webresources
  • List and manage
  • Upload / update / download
  • Watch a local filesystem and create/update/delete on the remote server
  • Settings
  • Set unsettable settings
  • Update records generically
  • By exporting the data using this CLI, you can move configuration or entity data to a new organization.
  • Run data imports using standard Dynamics data import capabilities.
  • Upload local files and use import maps just like the UI data import wizard but via the command line.
  • If you split your files before hand and upload in parallel, e.g. linux's parallel utilities, you can load 1M rec/hour.
  • Export data
  • Export entity datasets easily and quickly. CSV or json.
  • Export metadata of various kinds.
  • Token
  • Export a single, new auth token.
  • Continuously export a valid, refreshed token to a specific file.

有关详细信息,请参阅 dynamics-client

用于打包部分解决方案部署的成分在这里,因此您可以通过创建目录和标准脚本来创建自己的脚本化解决方案部署程序。

您可以使用通用的 GraphClient 来连接 Microsoft 应用程序的大部分内容并对其进行处理。

Credit

所有作品均由 The Trapelo Group 赞助。

License

麻省理工学院执照。 请参阅许可证文件。

版权所有 2017 The Trapelo Group LLC。

dynamicscli - a nodejs CLI application and client framework for working with online Microsoft Dynamics applications. The application will not currently authenticate with on-premise systems (or at least I do not think so).

dynamicscli uses the ODatav4 REST data api which means that you must register the application with Azure Active Directory to allow the CLI to connect to the server. Registering is easy to do, but you need Admin access to create the registration. You can use any application registration that allows your userid access to the data and has an application id.

dynamics-client two personalities:

  • A CLI that can be used from any OS. While one could use PowerShell for everything, its much easier to add commands or make commands robust using an application directly.
  • An extensive client library that is performant on the nodejs platform. You can use this as a framework for developing small Dynamics applications like ETL or platform management. For example, I added a command to help manage the dynamics platform in around 30 minutes and it worked the first time.

dynamicscli is written in scala.js which is a small language with more extensive type-safety, immutability and greater consistency. It is a great language for writing logic and effects heavy code.

Why nodejs? nodejs has an extensive array of web oriented resources and is lightweight on memory while still being fast enough. You could also use the client framework for CRM web applications directly. You can also use it for hot-reload, local development that seamlessly integrates with CRM so you get easy development of new CRM UI extensions. Running a nodejs instance on azure also means that you can deploy dynamicscli to azure and have a continuously running Dynamics platform processing platform ready to go.

dynamicscli automatically handles paging through multi-paged results from dynamics as well as automatic retry.

Installing

Currently, you need to build the solution from github. We will publish the CLI progarm on npm shortly.

npm i -g dynamics-client

Running

The script can be run, assuming it is on the path:

dynamicscli --help

If you need to run directly with node,

node /path/to/dynamicscli <args for dynamicscli>

CRM Connection Parameters

Dynamics connection parameters should be placed in a json file. The default is crm.json. The file should look like below. Some typical values are also shown but you must find the values that match your application.

{
    "tenant" : "<yourorgname>.onmicrosoft.com",
    "authorityHostUrl" : "https://login.windows.net",
    "username" : "<userid>@<tenant>",
    "password" : "<yourpassword>",
    "applicationId" : "<appid>",
    "dataUrl": "https://<yourorgname>.api.crm.dynamics.com/api/data/v8.2/",
    "acquireTokenResource": "https://<yourorg>.crm.dynamics.com"
}

Your password can also be in the environment variable DYNAMICS_PASSWORD as you should avoid passwords in config files that may get checked into version control.

The above shows the domain name to be <yourorg>.onmicrosoft.com but the domain varies, It could be mycompany.com. The dataUrl can be obtained from Developers page in the CRM application's Settings area. applicationId can only be obtained from our Azure Active Directory application's registration page. Sometimes, applicationId is called clientId. authorityHostUrl should only be changed if you know that you should change it, otherwise, leave it the same as the value above.

Some information can be inferred if left out. For example, the tenant can be inferred from username and the dataUrl can be inferred from acquireTokenResource but its best to specify them directly.

Once you have created your connection file, use it with the -c <connectionfile> option. If you connect to several organizations just name the connection file after the organization e.g. myorg1.json or myorg2.json then use it -c myorg1.json. Or, specify the config file in DYNAMICS_CRMCONFIG and skip providing the option on the command line.

If you are using Graph via the GraphClient, use the following parameters:

{
 ...
 "authorityHostUrl" : "https://login.microsoftonline.com",
 "dataUrl": "https://graph.microsoft.com/v1.0",
 "acquireTokenResource": "https://graph.microsoft.com",
  ...
}

You could also use https://outlook.office.com to access the outlook API directly at https://outlook.office.com/api/v2.0 for the data url.

Commands

The general CLI usage is dynamics command [subcommand] [opts].

Use dynamics --help to print out help and see the commands.

What can you do?

Some of the things you can do with the CLI include:

  • List and manage:
  • Publishers
  • Solutions
  • System jobs
  • Import maps
  • Execute actions (bound and unbound)
  • plugins (one-time or watch) update an assembly (.dll) that is already registered.
  • Option sets
  • Processes - Workflows
    • List/activate/deactivate/run (against a query)
  • SDK Messages
    • List/activate/deactivate
  • Webresources
  • List and manage
  • Upload / update / download
  • Watch a local filesystem and create/update/delete on the remote server
  • Settings
  • Set unsettable settings
  • Update records generically
  • By exporting the data using this CLI, you can move configuration or entity data to a new organization.
  • Run data imports using standard Dynamics data import capabilities.
  • Upload local files and use import maps just like the UI data import wizard but via the command line.
  • If you split your files before hand and upload in parallel, e.g. linux's parallel utilities, you can load 1M rec/hour.
  • Export data
  • Export entity datasets easily and quickly. CSV or json.
  • Export metadata of various kinds.
  • Token
  • Export a single, new auth token.
  • Continuously export a valid, refreshed token to a specific file.

See dynamics-client for details.

Ingredients for packaging up parts of a solution deployment are here so you can create your own scripted solution deployer by just creating a directory and a standard script.

You can use the general GraphClient to connect and run processing against much of the Microsoft app universe.

Credit

All work sponsored by The Trapelo Group.

License

MIT license. See the LICENSE file.

Copyright 2017 The Trapelo Group LLC.

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文