Basic CRUD using Xrm.WebApi
Dynamics 365 Customer Engagement v9 has added CRUD functionality to query the WebAPI endpoint using Client API.
Based on my initial analysis, this seems to be a work in progress and more functions will be added over time. This is some sample code how you can do the basic CRUD using this new feature. This is not an exhaustive documentation, but considering that there is nothing about this in the official documentation, it is a starting point.
Create : Method signature is Æ’ (entityType, data)
Sample code to create 3 contact records
[...new Array(3).keys()].forEach(x => Xrm.WebApi.createRecord('contact', { firstname: 'Test', lastname: `Contact${x}` }).then(c => console.log(`${x}: Contact with id ${c.id} created`)) .fail(e => console.log(e.message)))
Retrieve: Method signature is Æ’ (entityName, entityId, options)
Sample code to retrieve contact record based on the primary key
Xrm.WebApi.retrieveRecord('contact', 'cadf8ac6-17b1-e711-a842-000d3ad11148', '$select=telephone1') .then(x => console.log(`Telephone: ${x.telephone1}`)) .fail(e => console.log(e.message))
RetrieveMultiple: Method signature is f(entityType, options, maxPageSize)
Sample code to retrieve 10 contact records without any conditions.
Xrm.WebApi.retrieveMultipleRecords('contact', '$select=fullname,telephone1', 10) .then(x => x.entities.forEach(c => console.log(`Contact id: ${c.contactid}, fullname: ${c.fullname}, telephone1: ${c.telephone1}`))) .fail(e => console.log(e.message))
Update: Method signature is Æ’ (entityName, entityId, data)
Sample code to update field on contact record
Xrm.WebApi.updateRecord('contact', 'cadf8ac6-17b1-e711-a842-000d3ad11148', { telephone1: '12345' }).then(x => console.log(`Contact with id ${x.id} updated`)) .fail(x => console.log(x.message))<span data-mce-type="bookmark" id="mce_SELREST_start" data-mce-style="overflow:hidden;line-height:0" style="overflow:hidden;line-height:0" ></span>
Delete: Method signature is Æ’ (entityName, entityId)
Xrm.WebApi.deleteRecord('contact', '88E682D8-18B1-E711-A842-000D3AD11148') .then(c => console.log('Contact deleted')) .fail(x => console.log(x.message))
What is not yet done/appears to be in progress
- Xrm.WebApi.offline not yet implemented
- Ability to construct custom OData requests to pass into Xrm.WebApi.execute
- Batching multiple requests
You can use this on your client side code on v9. It is quite basic at the moment, but you don’t need to include any external libraries. But in more advanced scenarios, you can always use Xrm WebAPI Client till these features are made available in the Client API.

This was originally posted here.
*This post is locked for comments