Set Account Based on Contact
function SetAccountName(executionContext)
{
debugger;
var formContext = executionContext.getFormContext();
var contactID = formContext.data.entity.getId();
if (contactID != null) {
Xrm.WebApi.retrieveMultipleRecords("account", "?$select=" + "accountid" + "&$filter=" + "_primarycontactid_value" + " eq " + contactID).then(
function success(result) {
console.log(result);
if (result.entities.length > 0) {
var account = new Array();
account[0] = new Object();
account[0].entityType = "account";
account[0].id = result.entities[0]["accountid"];
account[0].name = result.entities[0]["accountid@OData.Community.Display.V1.FormattedValue"];
formContext.getAttribute("parentcustomerid").setValue(account);
}
else {
formContext.getAttribute("parentcustomerid").setValue();
formContext.getAttribute("parentcustomerid").setValue();
}},
function (error) {
alert(error.message);
}
);
}}