Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 8223

Update CRM online 2016 records from custom application using WEB API

$
0
0
I am using below code to update the crm records from custom html application(using CRM 2016 online web API). We have already registered our custom application using Azure Ad in O365 and the we are able to retrieve the records from CRM successfully in the custom application(Html).

Now  we are trying to update the MS CRM online 2016 records from custom application, application runs successfully without any error but the records are not updated in MS CRM. So while debugging my code i have received some error 


PATCH https://crmurl.crm.dynamics.com/api/data/v8.0/accounts(b2c9cceb-236c-e611-80db-c4346bb59860) (anonymous function) 
XMLHttpRequest cannot load https://crmurl.crm.dynamics.com/api/data/v8.0/accounts(b2c9cceb-236c-e611-80db-c4346bb59860). No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:65343' is therefore not allowed access. The response had HTTP status code 401.

here  http://localhost:65343 is my custom application url(same url registered in Azure Ad and i am able to retrieve records from CRM)

Update JS Code:

             var account = {};
               account["name"] = "Test"; 
               account["address1_city"] = "Test City"

              var req= new XMLHttpRequest();
               req.open("PATCH", "https://crmrocks.crm.dynamics.com/api/data/v8.0/accounts(" + id + ")", true);
               req.setRequestHeader("Accept", "application/json");
               req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
               req.setRequestHeader("OData-MaxVersion", "4.0");
               req.setRequestHeader("OData-Version", "4.0");
               req.setRequestHeader("Access-Control-Allow-Origin", "http://localhost:65343/Accounts.html");
//           req.setRequestHeader("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS");
//           req.setRequestHeader("Access-Control-Allow-Headers", "Content-Type");
               req.send(JSON.stringify(account));
               if (req.readyState == 4 /* complete */) {
                   if (req.status == 204) {
                       alert("Completed");
                   } else {
                       alert("Not Completed");
                   }
               }

Kindly help me to resolve this error.

Viewing all articles
Browse latest Browse all 8223

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>