RE: Auto populate a field based
Hi partner,
So you means you want the field A on form A be populated from field B on contact form based on the lookup value of contact in form A?
If so, please refer to the following code.
function getValueFromLookUp(executionContext){
var formContext=executionContext.getFormContext();
//get contact lookup field value on form A
var Lookup_Contact=formContext.getAttribute("Lookup_contact");
if(Lookup_Contact!=null){
//get contact record id
var value=Lookup_Contact.getValue();
var id=value[0].id;
//use record id to retrieve field B on contact form
Xrm.WebApi.retrieveRecord("contact",id,"?$select=fieldB").then(
function success(result){
//get the field B value and set it to field A
var fieldB=result.fieldB;
formContext.getAttribute("fieldA").setValue(fieldB);
},
function (error){
console.log(error.message);
}
)
}
}
Add this JS function to form A contact lookup field onchange event.
Remember to click "Pass execution context as first parameter"

Best Regards,
Leo