Hi,
Once you get the contact id, you need to fetch the account from that contact. For this you can use WEB API.
Below is the sample code. You need to update the field schema name as per your organization
=============
function onChangeFrom() {
var party = Xrm.Page.getAttribute("from");
var members = party.getValue();
if (members != null) {
for (var i = 0; i < members.length; i++) {
if (members[i].type == 2) {
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/contacts(" + members[i].id.replace("{", "").replace("}", "") + ")?$select=_parentcustomerid_value", 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 _parentcustomerid_value = result["_parentcustomerid_value"];
var _parentcustomerid_value_formatted = result["_parentcustomerid_value@OData.Community.Display.V1.FormattedValue"];
var _parentcustomerid_value_lookuplogicalname = result["_parentcustomerid_value@Microsoft.Dynamics.CRM.lookuplogicalname"];
// Create lookup object
var accountLookup = new Array();
accountLookup[0] = new Object();
accountLookup[0].id = _parentcustomerid_value;
accountLookup[0].name = _parentcustomerid_value_formatted;
accountLookup[0].entityType = _parentcustomerid_value_lookuplogicalname;
Xrm.Page.getAttribute("new_fromaccount").setValue(accountLookup);
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
}
}
}
}
================================
Hope this helps.