function getContactDetails()
{
var lookUpObjectValue = Xrm.Page.getAttribute("customerid").getValue();
if ((lookUpObjectValue != null))
{
var lookuptextvalue = lookUpObjectValue[0].name;
var lookupid = lookUpObjectValue[0].id;
// alert(lookupid);
var serverUrl = Xrm.Page.context.getServerUrl();
//The XRM OData end-point
var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";
var odataSetName = "AccountSet";
var odataSelect = serverUrl + ODATA_ENDPOINT + "/" + odataSetName + "(guid'" + lookupid + "')";
//alert(odataSelect);
$.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) {
var result_contact= data.d;
var mc_city1 = result_contact.Address1_City;
//replace the fields with the fields on your entity
Xrm.Page.getAttribute("shipto_city").setValue(mc_city1);
Xrm.Page.getAttribute("shipto_line1").setValue(result_contact.Address1_Line1);
Xrm.Page.getAttribute("shipto_line2").setValue(result_contact.Address1_Line2);
Xrm.Page.getAttribute("shipto_line3").setValue(result_contact.Address1_Line3);
Xrm.Page.getAttribute("shipto_fax").setValue(result_contact.Fax);
Xrm.Page.getAttribute("shipto_telephone").setValue(result_contact.Telephone1);
Xrm.Page.getAttribute("shipto_name").setValue(result_contact.Address1_PrimaryContactName);
Xrm.Page.getAttribute("shipto_stateorprovince").setValue(result_contact.Address1_StateOrProvince);
Xrm.Page.getAttribute("shipto_postalcode").setValue(result_contact.Address1_PostalCode);
Xrm.Page.getAttribute("shipto_country").setValue(result_contact.Address1_Country);
Xrm.Page.getAttribute("shippingmethodcode").setValue(result_contact.Address1_ShippingMethodCode.Value);
Xrm.Page.getAttribute("paymenttermscode").setValue(result_contact.PaymentTermsCode.Value);
//billto addresp
Xrm.Page.getAttribute("billto_city").setValue(mc_city1);
Xrm.Page.getAttribute("billto_line1").setValue(result_contact.Address1_Line1);
Xrm.Page.getAttribute("billto_line2").setValue(result_contact.Address1_Line2);
Xrm.Page.getAttribute("billto_line3").setValue(result_contact.Address1_Line3);
Xrm.Page.getAttribute("billto_fax").setValue(result_contact.Fax);
Xrm.Page.getAttribute("billto_telephone").setValue(result_contact.Telephone1);
Xrm.Page.getAttribute("billto_name").setValue(result_contact.Address1_PrimaryContactName);
Xrm.Page.getAttribute("billto_stateorprovince").setValue(result_contact.Address1_StateOrProvince);
Xrm.Page.getAttribute("billto_postalcode").setValue(result_contact.Address1_PostalCode);
Xrm.Page.getAttribute("billto_country").setValue(result_contact.Address1_Country);
//Xrm.Page.getAttribute("shipto_line2").setValue(result_contact.Paymenttermscode);
//paymnt term code
},
error: function (XmlHttpRequest, textStatus, errorThrown) { alert('OData Select Failed: ' + odataSelect); }
});
}
}
No comments:
Post a Comment