With Microsoft releasing Dynamics 365 update 9.0, now, we have a new library to implement WebAPI methods using Xrm.WebApi. Instead of writing the complete request, now we can just use direct the CRUD methods from the Web API.
If you are looking for how to write Web API for Dynamics CRM 2016, check out the sample index here.
Xrm.WebApi has two properties to use for the Online and the Offline client respectively. In this article, we are going to implement a sample HTML web resource using Xrm.WebApi for the online client.
- function createAccount() {
- // collect account data
- var data = {
- "name": document.getElementById("txtname").value,
- "address1_city": document.getElementById("txtcity").value,
- "telephone1": document.getElementById("txtphone").value,
- "numberofemployees": document.getElementById("txttotalemployees").value,
- "websiteurl": document.getElementById("txtwebsite").value
- }
- // create account record
- parent.Xrm.WebApi.createRecord("account", data).then(
- function success(result) {
- document.getElementById("txtaccountid").value = result.id;
- alert("Account Created !!");
- },
- function(error) {
- alert(error.message);
- }
- );
- }
- function updateAccount() {
- // collect account data
- var data = {
- "name": document.getElementById("txtname").value,
- "address1_city": document.getElementById("txtcity").value,
- "telephone1": document.getElementById("txtphone").value,
- "numberofemployees": document.getElementById("txttotalemployees").value,
- "websiteurl": document.getElementById("txtwebsite").value
- }
- //get account id
- var accountId = document.getElementById("txtaccountid").value;
- // update account record
- parent.Xrm.WebApi.updateRecord("account", accountId, data).then(
- function success(result) {
- alert("Account Record Updated");
- },
- function(error) {
- alert(error.message);
- }
- );
- }
- function deleteAccount() {
- var accountId = document.getElementById("txtaccountid").value;
- parent.Xrm.WebApi.deleteRecord("account", accountId).then(
- function success(result) {
- alert("Account deleted");
- },
- function(error) {
- alert(error.message);
- }
- );
- }

You can download the complete code from GitHub here. Stay tuned for more Dynamics 365 update 9.0 features !!!







Ravee SinghPosted Jun 7, 2018, 4:49 PM EDT
Great work very helpful for new guys like me can you please suggest something to complete business process flow as i upload data in crm online 8.2 ver
Ravee SinghPosted Jun 7, 2018, 4:46 PM EDT
Hi mahender,