In this blog, we will show how populate lookup value to multiple fields

For this blog, i have created a lookup field and 3 text fields. if we select any record in the lookup and it will auto populate to the 3 text fields.

if we select any record in the application field and it will populate data to the father, mail and coun fields.

for this i have created the below code to retrieve the records from the lookup.

function updateFields(executionContext) {
var formContext = executionContext.getFormContext();
var testLookup = formContext.getAttribute(“vinay_application”).getValue();

if (testLookup != null) {
var testLookupid = testLookup[0].id.replace(‘{‘, ”).replace(‘}’, ”);
Xrm.WebApi.retrieveRecord(“vinay_applicantsprofile”, testLookupid, “?$select=vinay_fathersname, vinay_email, vinay_count”).then(
function success(result) {
console.log(result);
var vinay_applicantsprofileid = result[“vinay_applicantsprofileid”]; // Guid
var account = result[“vinay_fathersname”]; // Text
if (account != null) {
formContext.getAttribute(“vinay_father”).setValue(account);
}
var mail = result[“vinay_email”]; // Text
if (mail != null) {
formContext.getAttribute(“vinay_mail”).setValue(mail);
}
var counts = result[“vinay_count”]; // Text
if (counts != null) {
formContext.getAttribute(“vinay_coun”).setValue(counts);
}
},
function (error) {
console.log(error.message);
}
);
}
else{
formContext.getAttribute(“vinay_coun”).setValue(null);
formContext.getAttribute(“vinay_mail”).setValue(null);
formContext.getAttribute(“vinay_father”).setValue(null);
}
}

Before selecting a record

After selecting a record in the application it is populated the data to the given fields

For any help or Queries contact us on info@crmonce.com or +918096556344