There are two entities
1. Contact
2. Customer
I will try to retrieve field value from contact(field name mobile) and update to Customer(field name sbl_contact_mobile) with below code but field value should be blank.So please check and correction of my code.
function GetDataOnChange()
{
var custid = Xrm.Page.getAttribute("parentaccountid").getValue()[0].id;
if(custid !=null) {
var cid =custid.replace("{","").replace("}","");
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/contacts("+cid+")?$select=mobilephone", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function() {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response);
var contmobile = result["mobilephone"]; // will return value example - 8
Xrm.Page.getAttribute("sbl_contact_mobile").setValue(contmobile);
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
}
}