function GetCity()
{
var serverUrl = "http://"+window.location.host+"/" + Xrm.Page.context.getOrgUniqueName();
var id = Xrm.Page.getAttribute("new_courtid").getValue();
if(id!=null)
{
var ODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc";
var retrieveReq = new XMLHttpRequest();
//replace with your odata query
var Odata = ODataPath + "/AccountSet?$select=new_city&$filter=accountId eq guid'" + id[0].id + "'";
retrieveReq.open("GET", Odata, true);
retrieveReq.setRequestHeader("Accept", "application/json");
retrieveReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
retrieveReq.onreadystatechange = function () { retrieveReqCallBack(this); };
retrieveReq.send();
}
}
function retrieveReqCallBack(retrieveReq) {
if (retrieveReq.readyState == 4 /* complete */) {
if (retrieveReq.status == 200) {
var retrieved = JSON.parse(retrieveReq.responseText).d;
//replace attribute name as in the query
var city= retrieved.results[0]["new_city"];
Xrm.Page.data.entity.attributes.get('new_city').setValue(city.Value);
}
else {
errorHandler(retrieveReq);
alert("Unable to Retrieve City");
}
}
}
No comments:
Post a Comment