Hi,
In the case form I want to autofill Company Lookup field as soon as Project Lookup field is set. (OnChange)
Generally it works but it shows (No Name) instead of the company name, so when i click on No name, it forwards me to the correct company.
I am retrieving the Project data and getting the company id, then I retrieve via relationship the comany name.
My code looks like this
functionsetCompany(executionContext) {
varformContext = executionContext.getFormContext();
// Get the value of lookup field A
varproject = formContext.getAttribute("skt_pde_project").getValue();
// Get the record associated with lookup field A
varproject = project[0].id;
// Retrieve the value of field B from the associated record
Xrm.WebApi.retrieveRecord("pde_project", project, "?$select=_pde_account_id_value").then(
functionsuccess(result) {
console.log(result);
// Columns
varpde_projectid = result["pde_projectid"]; // Guid
varpde_account_id = result["_pde_account_id_value"]; // Lookup
varpde_account_id_formatted = result["_pde_account_id_value@OData.Community.Display.V1.FormattedValue"];
varpde_account_id_lookuplogicalname = result["_pde_account_id_value@Microsoft.Dynamics.CRM.lookuplogicalname"];
if (result.hasOwnProperty("pde_account_id") && result["pde_account_id"] !== null) {
varpde_account_id_name = result["pde_account_id"]["name"]; // Text
}
// Set the value of lookup field B
formContext.getAttribute("customerid").setValue([{ id:pde_account_id, name:pde_account_id_name, entityType:pde_account_id_lookuplogicalname }]);
},
function (error) {
console.log(error.message);
}
);
}






