Hi Victoria,
You can do this using webapi and client side scripting.
You would get the id of the contact using script:
var contactId = Xrm.Page.getAttribute("contactid").getValue();
You would then call the following api passing the contact id to it;
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/contacts(" + contactId + ")?$select=_accountid_value&$expand=parentcustomerid_account($select=name,telephone1)", 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 _accountid_value = result["_accountid_value"];
var _accountid_value_formatted = result["_accountid_value@OData.Community.Display.V1.FormattedValue"];
var _accountid_value_lookuplogicalname = result["_accountid_value@Microsoft.Dynamics.CRM.lookuplogicalname"];
if (result.hasOwnProperty("parentcustomerid_account")) {
// These are the name and phone fields.
var parentcustomerid_account_name = result["parentcustomerid_account"]["name"];
var parentcustomerid_account_telephone1 = result["parentcustomerid_account"]["telephone1"];
// Use setValue to populate the fields.
var contactId = Xrm.Page.getAttribute("telephone1").setValue(parentcustomerid_account_telephone1);
}
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
Hope this helps.