Create more applications using the Microsoft Dynamics Xrm platform, enables querying the dynamics data model from any application.
npm install more-xrm
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.
Query interface for describing columns, filters and other query information
Query, with formatting and attribute alias names
Batch interface for describing changesets and committing them in batch
authToken with an associated system user record can be used.
html
``
>_or_
From npm:
`bash
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:
`typescript
const accounts = query('account')
.path('accounts') // Indicates Entity Name on Web API Url
.where('name', QueryOperator.Contains, 'xrm')
.orderBy('name')
.select('name');
`
4. Call dynamics to obtain a connection to Dynamics:
> const dynamicsClient = dynamics(); //option to pass access token
5. Execute accounts query using dynamicsClient:
`typescript
dynamicsClient.fetch(accounts).then(results => { / results is an array of accounts / });
`
6. Update data in Dynamics by calling save:
`typescript
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'_
`typescript
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 /
});
}
});
``