more-xrm
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

more-xrm

npm

Create more applications using the Microsoft Dynamics 365/XRM platform

more-xrm is a TypeScript library that enables you to connect, query and manage Dynamics 365 data using the modern fetch api. Query operations and batch procedures are available for connecting to the Dynamics Web API.

more-xrm enables querying the dynamics data model from any application

  • provides methods for querying and managing Dynamics 365 data
  • introduces Query interface for describing columns, filters and other query information
  • provides an easy way to retrieve data for a Query, with formatting and attribute alias names
  • introduces Batch interface for describing changesets and committing them in batch
    • automatically sets related identifiers for parental records created within the same batch
  • provides methods for querying and managing Dynamics 365 Entity Metadata
  • retrieve information about Entities, Attributes and OptionSets in a concise format
  • request metadata for multiple entities and their attributes using a batch operation

Installation

This module is designed for use with Microsoft Dynamics 365 Customer Engagement Web API - either a Web Resource with a relative api path or an authToken with an associated system user record can be used.

From unpkg (cdn):

<script src="https://unpkg.com/more-xrm"></script>

or

From npm:

npm install more-xrm

How to use

  1. Import/Add the dynamics method from 'more-xrm/dist/Dynamics'

    import dynamics from 'more-xrm/dist/Dynamics';

  2. Import/Add query method and QueryOperator enum from 'more-xrm/dist/Query'

    import query, { QueryOperator } from 'more-xrm/dist/Query';

  3. Create a query for the Dynamics Account entity:

const accounts = query('account')
                    .path('accounts') // Indicates Entity Name on Web API Url
                    .where('name', QueryOperator.Contains, 'xrm')
                    .orderBy('name')
                    .select('name');
  1. Call dynamics to obtain a connection to Dynamics:

    const dynamicsClient = dynamics(); //option to pass access token

  2. Execute accounts query using dynamicsClient:

dynamicsClient.fetch(accounts).then(results => { /* results is an array of accounts */ });
  1. Update data in Dynamics by calling save:
const accountId = accounts[0].accountid; //account with name like '%xrm%'
dynamicsClient.save('accounts', { name: 'more-xrm' }, accountId).then(id => { /* id of account */ });

Example

An application will query the Account entity in Dynamics where the name contains 'xrm', then update the Account name to 'more-xrm'

import dynamics from 'more-xrm/dist/Dynamics';
import query, { QueryOperator } from 'more-xrm/dist/Query';
 
//Create a query
const accounts = query('account')
                    .path('accounts') // Indicates Entity Name on Web API Url
                    .where('name', QueryOperator.Contains, 'xrm')
                    .orderBy('name')
                    .select('name');
 
//Connect to Dynamics
const dynamicsClient = dynamics();
 
//Execute accounts query
dynamicsClient.fetch(accounts).then(results => { 
 
    if(results.length > 0) {
        const accountId = accounts[0].accountid;
 
        //Update data in Dynamics by calling save:
        dynamicsClient.save('accounts', { name: 'more-xrm' }, accountId).then(id => {
            
            /* Account was updated */
 
        });
    }
});
 

License

MIT License

more-xrm is licensed under the MIT license

Package Sidebar

Install

npm i more-xrm

Weekly Downloads

2

Version

0.1.2

License

MIT

Unpacked Size

200 kB

Total Files

55

Last publish

Collaborators

  • gregd