Hi
I am trying to debug this javascript , and this has some old code, please help in finding all the mistakes,
Thanks
var appUrl = "">orgd38959de.crm5.dynamics.com/"; function onFormLoad() { Xrm.Page.getAttribute("parentaccount").addOnChange(openRecord); setEmployeeNumber(); } function openRecord() { var recordId = Xrm.Page.getAttribute("parentcustomerid").getValue(); var url = appUrl + "/main.aspx?pagetype=entityrecord&etn=account&id=" + recordId; window.open(url); } function setEmployeeNumber() { var recordId = Xrm.Page.getAttribute("parentcustomerid").getValue(); var req = new XMLHttpRequest(); req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/contacts?$filter=_parentcustomerid_value eq" + recordId + "&$count=true", true); req.setRequestHeader("OData-MaxVersion", "4.0"); req.setRequestHeader("OData-Version", "4.0"); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); req.setRequestHeader("Prefer", "odata.include-annotations=\"*\""); req.onreadystatechange = function () { if (this.readyState === 4) { req.onreadystatechange = null; if (this.status === 200) { var results = JSON.parse(this.response); var recordCount = results["@odata.count"]; Xrm.Page.getAttribute("employeeid").setValue(recordCount); var entity = {}; entity.numberofemployees = recordCount; Xrm.WebApi.online.updateRecord("account", recordId, entity).then( function success(result) { var updatedEntityId = result.id; }, function (error) { Xrm.Utility.alertDialog(error.message); } ); } else { Xrm.Utility.alertDialog(this.statusText); } } }; req.send(); }