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!
Create Entity Record
To create an entity record, we can simply call Xrm.WebApi create Record using the following parameters.
- Entity logical name
- Entity object
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.
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.
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:
- Entity logical name
- Entity GUID
- Entity object
Delete Entity Record
To delete record from CRM, use Xrm.WebApi.delete Record.
The parameters of this function are shown below:
- Entity logical name
- Entity GUID
Retrieve Single Entity Record
Use following syntax to retrieve single entity record:
Retrieve Multiple Records
Use following syntax to retrieve multiple records:
Retrieve Related Entity Record
Use following syntax to retrieve related entity record:
Explore Dynamics 365 Services!
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!