Dynamics 365 v9.0: Xrm.WebApi – CRUD Operations

V9.0 has loads of new and exciting features. One of the most exciting improvement, at least for developers, is Xrm.WebApi. Prior to v9.0, to perform CRUD operations in Dynamics CRM, either we had to make our own library, utilize external libraries or create custom request using XmlHttpRequest and ajax. Xrm.WebApi is a cool improvement included in Dynamics 365 v9.0 which will make it easier for developers to perform CRUD operations.

Learn more about Dynamics 365 Services!

Learn More

Create Entity Record

To create an entity record, we can simply call Xrm.WebApi create Record using the following parameters.

  1. Entity logical name
  2. Entity object

Xrm.WebApi create Record

Associate Existing Entity Record

To associate new entity records to existing entity records, set the value of single-valued navigation properties using the @odata.bind annotation. The following example creates a contact record and associates it to an existing account record.

associate new entity records to existing entity records

Create Related Entity Records

In Dynamics CRM, we also need to relate records with each other. For example, any opportunity is related to any account record. When creating an account record, we need to relate another record with it.  Flowing is the code to relate opportunity with account entity.

Dynamics CRM Related Entity Records

Update Entity Record

To update the record, we will create object of the entity and then set the fields and its value, that we need to update and then call Xrm.WebApi.updateRecord function to create the record in CRM. The parameters of this function are as shown below:

  1. Entity logical name
  2. Entity GUID
  3. Entity object

Xrm.WebApi.updateRecord function

Delete Entity Record

To delete record from CRM, use Xrm.WebApi.delete Record.

The parameters of this function are shown below:

  1. Entity logical name
  2. Entity GUID

delete record from CRM

Retrieve Single Entity Record

Use following syntax to retrieve single entity record:

syntax to retrieve single entity record

Retrieve Multiple Records

Use following syntax to retrieve multiple records:

syntax to retrieve multiple records

Retrieve Related Entity Record

Use following syntax to retrieve related entity record:

syntax to retrieve related entity record

Explore Dynamics 365 Services!

Learn More

Conclusion

Above described is the method to customize and to perform create, insert, update, delete as well as to associate operations in Dynamics CRM using V9.0 web API. Web API provides us much simpler way to perform crud apportions as compare to old OData methods.

If you have any question or queries, do not hesitate to reach out to us