Hi Guys,
I getting error ,
Error: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'localhost/.../GetPostalCode'.
at CountriesList (crmapi365.crm.dynamics.com/.../astro_Country)
at eval (eval at RunHandlerInternal (crmapi365.crm.dynamics.com/.../ClientApiWrapper.aspx), <anonymous>:1:1)
at RunHandlerInternal (crmapi365.crm.dynamics.com/.../ClientApiWrapper.aspx)
at RunHandlers (crmapi365.crm.dynamics.com/.../ClientApiWrapper.aspx)
at OnScriptTagLoaded (crmapi365.crm.dynamics.com/.../ClientApiWrapper.aspx)
at crmapi365.crm.dynamics.com/.../ClientApiWrapper.aspx
Note:- I am trying to call other domain API from Dynamic CRM 365.
Code:-
//||**** This function fire when form is load*****||
"use strict";
function CountriesList()
{
var url = Xrm.Page.context.getClientUrl();
Xrm.Page.getAttribute("address1_country").setRequiredLevel("required");
Xrm.Page.getAttribute("address1_stateorprovince").setRequiredLevel("required");
var xhttp = new XMLHttpRequest();
//xhttp.open("GET", "astrocrmapi.azurewebsites.net/.../GetPostalCode", false);
xhttp.open("GET", "localhost/.../GetPostalCode", false);
//xhttp.open("GET", "astrodevapi.azurewebsites.net/.../GetPostalCode", false);
xhttp.setRequestHeader("Content-type", "application/json");
xhttp.setRequestHeader("Accept", "application/json");
xhttp.setRequestHeader("Content-Type", "application/json; charset=utf-8");
xhttp.send();
var response = JSON.parse(xhttp.responseText);
function KeyPressDataLoad (ext)
{
var userInput = Xrm.Page.getControl("address1_country").getValue();
var resultSet =
{
results: new Array(),
commands:
{
id: "country",
//This will add the Link at the bottom of the auto complete search result
//icon: url + "/WebResources/new_AddImage",
//icon: url + "/WebResources/astro_AddImage",
label: "New",
action: function ()
{
//specify the action that you want to perform on click of New Link
//window.open("demoannik.crm8.dynamics.com");
window.open(url);
}
}
};
var userInputLowerCase = userInput.toLowerCase();
for (var i = 0; i < response.length; i++)
{
if (userInputLowerCase === response[i].NameCRM.substring(0, userInputLowerCase.length).toLowerCase())
{
resultSet.results.push({
id: i,
fields: [response[i].NameCRM, ]//,
//icon: url + "/WebResources/new_testingFlag"
// icon: url + "/WebResources/astro_testingFlag"
});
}
if (resultSet.results.length >= 2000)
{
break;
}
}
if (resultSet.results.length > 0)
{
ext.getEventSource().showAutoComplete(resultSet);
}
else
{
ext.getEventSource().hideAutoComplete();
}
}
Xrm.Page.getControl("address1_country").addOnKeyPress(KeyPressDataLoad);
}






