Read Quick View form fields using Javascript in Dataverse Form/Dynamics 365 Forms

Sometimes in your projects you need to read Fields displayed in Quick View Form using JavaScript. This post help you how to read Quick View Form Fields in Javascript. Here is the sample code.
This function retrieves a field value from a Quick View Form when a model-driven form loads. Below is a detailed breakdown of how it works:
var contactQuickViewCtrl = formContext.ui.quickForms.get("account_contact_quickview");
- Retrieves the Quick View control named
"account_contact_quickview"
. - A Quick View control displays related entity records within a form (e.g., showing a Contact’s details inside an Account form).
var fullname = contactQuickViewCtrl.getControl("fullname").getAttribute().getValue();
- Retrieves the
fullname
field value from the Quick View form. - Expected outcome: The variable
fullname
stores the Contact’s full name.
function getQuickViewField_onLoad(context) {
var formContext = context.getFormContext();
var contactQuickViewCtrl = formContext.ui.quickForms.get("account_contact_quickview");
if (contactQuickViewCtrl != undefined) {
if (contactQuickViewCtrl .isLoaded()) {
var fullname= contactQuickViewCtrl.getControl("fullname").getAttribute().getValue();
}
}