Hello Experts,
Can I know, if the custom field. How to write in Query OData? It is using 'new_TaxRateSet' or 'new_taxrateSet' ? I write code which is to get new_percentage at new_taxrate based on new_customertaxcode and new_producttaxcode in quotedetail. It run successfully but it not get the value of new_percentage in new_taxrate. Can someone tell me it is wrong in my code?
function getTaxCode() { debugger; var taxRatePercent = null; var taxrateId = null; var customerTaxCodeObj = Xrm.Page.data.entity.attributes.get("new_customertaxcode"); var productTaxCodeObj = Xrm.Page.data.entity.attributes.get("new_producttaxcode"); if (customerTaxCodeObj.getValue() != null) { var entityIdCust = customerTaxCodeObj.getValue()[0].id; var entityNameCust = customerTaxCodeObj.getValue()[0].entityType; var entityLabelCust = customerTaxCodeObj.getValue()[0].name; if (productTaxCodeObj.getValue() != null) { var entityIdProd = productTaxCodeObj.getValue()[0].id; var entityNameProd = productTaxCodeObj.getValue()[0].entityType; var entityLabelProd = productTaxCodeObj.getValue()[0].name; // Get CRM Context var context = Xrm.Page.context; var serverUrl = context.getClientUrl(); // Cater for URL differences between on-premise and online if (serverUrl.match(/\/$/)) { serverUrl = serverUrl.substring(0, serverUrl.length - 1); } // Define ODATA query var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc"; var ODATA_EntityCollection = "/new_taxrateSet"; var QUERY = "?$select=new_Percentage&$filter=new_CustomerTaxCode eq '" + entityLabelCust + "'and new_ProductTaxCode eq '" + entityLabelProd + "'&$top=1"; var URL = serverUrl + ODATA_ENDPOINT + ODATA_EntityCollection + QUERY; var req = new XMLHttpRequest(); req.open("GET", URL, true); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); req.onreadystatechange = function () { if (this.readyState === 4) { this.onreadystatechange = null; var result = JSON.parse(this.responseText).d; var percentage = result.new_Percentage; calcTaxRate(percentage); } }; req.send(); } } }