hi Shiva,
1. You need to change in your AuthServer config file which provied you Token
ex. <system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Origin, X-
Requested-With, Content-Type, Accept,Authorization" />
<add name="Access-Control-Allow-Methods" value="GET, POST, PUT,
DELETE, OPTIONS" />
</customHeaders>
</httpProtocol>
</system.webServer>
2. I am using javascript file for CRM . Code working on addOnKeyPress fuction .
ex. //||***** This function fire addOnKeyPress of address1_city Text box. This is the auto complete ******* ||
"use strict";
Xrm.Page.getControl("address1_composite_compositionLinkControl_address1_city").addOnKeyPress(function (ext) {
var response;
var CountryCode = null;
var StateCode = null;
var PCode = null;
var userEmail;
var NotificationID;
var NotificationMessage;
var FirstName;
var LastName;
var xhttp = new XMLHttpRequest();
//This is Qrganization UniqueCode Like:- orgc9f08190
var OrganizationCodeName = Xrm.Page.context.getOrgUniqueName();
//This is the Client login URl
var clientUrl = Xrm.Page.context.getClientUrl();
//This is the host Api Url
var apiUrl = "[View:https://XYZ.azurewebsites.net/api/CRM/GetCRMData:750:50]";
//*************** Start ---- Get the user Information ----- **********************//
var ODataPath = clientUrl + "/XRMServices/2011/OrganizationData.svc";
var userRequest = new XMLHttpRequest();
userRequest.open("GET", ODataPath + "/SystemUserSet(guid'" + Xrm.Page.context.getUserId() + "')", false);
userRequest.setRequestHeader("Accept", "application/json");
userRequest.setRequestHeader("Content-Type", "application/json; charset=utf-8");
userRequest.send();
if (userRequest.status === 200) {
var retrievedUser = JSON.parse(userRequest.responseText).d;
//This is the Current user Email ID
userEmail = retrievedUser.InternalEMailAddress;
FirstName = retrievedUser.FirstName;
LastName = retrievedUser.LastName;
}
//*************** END ---- Get the user Information--- ***********************************//
if (Xrm.Page.getAttribute("address1_country").getValue() !== null) {
CountryCode = Xrm.Page.getAttribute("address1_country").getValue();
}
if (Xrm.Page.getAttribute("address1_stateorprovince").getValue() !== null) {
StateCode = Xrm.Page.getAttribute("address1_stateorprovince").getValue();
}
var CityCode = Xrm.Page.getControl("address1_composite_compositionLinkControl_address1_city").getValue();
if (Xrm.Page.getAttribute("address1_postalcode").getValue() !== null) {
PCode = Xrm.Page.getAttribute("address1_postalcode").getValue();
}
if (CityCode.length >= 2) {
var params = "CountryCRM=" + CountryCode + "&StateCRM=" + StateCode +
"&CityCRM=" + CityCode + "&PostalCodeCRM=" + PCode + "&flag=3" + "&OrganizationUrl=" + clientUrl + "&OrganizationUniqueName=" + OrganizationCodeName + "&UserEmail=" + userEmail + "&UserFirstName=" + FirstName + "&UserLastName=" + LastName;
xhttp.open("POST", apiUrl, true);
xhttp.setRequestHeader("Accept", "application/json");
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send(params);
xhttp.onreadystatechange = function ()
{
//Call a function when the state changes.
if (xhttp.readyState === 4 && xhttp.status === 200) {
response = JSON.parse(xhttp.responseText);
var resultSet =
{
results: new Array(),
commands:
{
id: "City",
label: "New",
action: function () {
window.open(clientUrl);
}
}
};
var userInputLowerCase = CityCode.toLowerCase();
for (var i = 0; i < response.length; i++) {
resultSet.results.push({
id: i,
fields: [response[i].NameCRM, ]
});
if (resultSet.results.length >= response.length) {
break;
}
}
if (resultSet.results.length > 0) {
ext.getEventSource().showAutoComplete(resultSet);
}
else {
ext.getEventSource().hideAutoComplete();
}
}
}
}
});