I have been working on CRM autoupdate filed and i got it working by
var lookUpObjectValue = Xrm.Page.getAttribute("new_kdid").getValue();
if ((lookUpObjectValue != null))
{
var lookupid = lookUpObjectValue[0].id;
var serverUrl = Xrm.Page.context.getServerUrl();
var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";
var odataSetName = "new_kdSet?";
var odataSelect = serverUrl + ODATA_ENDPOINT + "/" + odataSetName +
"$select=new_City" +
"&$filter=new_kdId eq (guid'" + lookupid + "')" +
"&$top=1";
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: odataSelect,
beforeSend: function (XMLHttpRequest) {XMLHttpRequest.setRequestHeader("Accept", "application/json"); },
success: function (data, textStatus, XmlHttpRequest){
Xrm.Page.getAttribute("address1_city").setValue(data.d.results[0].new_City);
},
error: function (XmlHttpRequest, textStatus, errorThrown) { alert('OData Select Failed: ' + odataSelect); }
});
}
And it works fine until I connect to CRM by IP. Like http://193.92.1.4/CRMTest/main.aspx# instead of crm-server01/CRMTest/main.aspx
then i get the error OData Select Failed:/*Some url that start with crm-server01/ ... */ and when i run it it get the right data?
This is down to cross site scripting. You will find this happens to a lot of different JavaScript doing requests on CRM.
I would recommend only connecting to CRM using your server name.