Please follow below step
Step 1- declare
var globalContext = Xrm.Utility.getGlobalContext();
Step 2- csjs.clientURLVersion() need to replace with globalContext.getClientUrl();
Step 3- I can see still space is there in the quotation which i have given because you to understand. Remove the space first and then I would suggest try to debug and get the query with complete url with value in a notepad then browse with chrome browser see what error you are getting.
You should get url like below -
https:\\xxxxxx/api/data/v8.2/accounts?$select=new_newcode,new_physicaladdress,new_physicalcity,new_physicalstate,new_physicalzip,name&$filter=new_newcode eq 'CODENO'
Replace xxxxx with your server url name.
Here the code should be look like, Try with this -
function CodeDetails(executionContext) {
debugger;
formContext = executionContext.getFormContext();
var globalContext = Xrm.Utility.getGlobalContext();
var FromCode = formContext.getAttribute("new_fromcode").getValue();
var ToCode = formContext.getAttribute("new_tocode").getValue();
var result;
var req = new XMLHttpRequest();
req.open("GET", globalContext.getClientUrl()+ "/api/data/v8.2/accounts?$select=new_newcode,new_physicaladdress,new_physicalcity,new_physicalstate,new_physicalzip,name&$filter=new_newcode eq '" + FromCode + "'", 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"];
for (var i = 0; i < results.value.length; i++) {
var new_newcode = results.value[i]["new_newcode"];
var new_physicaladdress = results.value[i]["new_physicaladdress"];
var new_physicalcity = results.value[i]["new_physicalcity"];
var new_physicalstate = results.value[i]["new_physicalstate"];
var new_physicalstate_formatted = results.value[i]["new_physicalstate@OData.Community.Display.V1.FormattedValue"];
var new_physicalzip = results.value[i]["new_physicalzip"];
var name = results.value[i]["name"];
formContext.getAttribute("new_detaildescription").setValue(new_physicaladdress);
}
}
else {
csjs.openAlertDialog(this.statusText);
}
}
};
req.send();
}