ACCESS FIELDS OF QUICK VIEW FORM THROUGH JAVASCRIPT IN DYNAMICS 365
Published Friday, January 6, 2023
As known, quick view controls are associated to lookup fields that are included in a form and they are added to display specific information about the selected record in the lookup field.
This will increase user experience where the users do not need to navigate to a different record to see the information needed.
However, you might have requirements where you want to check a field value of the quick view form control in order to apply specific behavior on the main form.
In this post, we will see how to access Quick View Form fields through JavaScript in Dynamics 365.
Based on the primary contact Relationship Type field, a specific section on the account form will be displayed.
- Relationship Type field of the contact = Employee => Employee section on the account form will be displayed
- Relationship Type field of the contact = Partner => Partner section on the account form will be displayed
- Relationship Type field of the contact = Client => Client section on the account form will be displayed
- Finally, the following JavaScript function can be used to manage the access of the Quick Find form fields and called on the account’s form onload and primary contact field onchange events
function showHideSectionsBasedOnQuickViewField(context) {
var formContext = context.getFormContext();
var contactQuickViewControl = formContext.ui.quickForms.get("account_contact_quickview");
if (contactQuickViewControl !== undefined) {
if (contactQuickViewControl.isLoaded()) {
var relationshipType = contactQuickViewControl.getControl("customertypecode").getAttribute().getValue();
switch (relationshipType) {
case 1: // Employee
formContext.ui.tabs.get("SUMMARY_TAB").sections.get("SUMMARY_TAB_section_employee").setVisible(true);
formContext.ui.tabs.get("SUMMARY_TAB").sections.get("SUMMARY_TAB_section_partner").setVisible(false);
formContext.ui.tabs.get("SUMMARY_TAB").sections.get("SUMMARY_TAB_section_client").setVisible(false);
break;
case 2: // Partner
formContext.ui.tabs.get("SUMMARY_TAB").sections.get("SUMMARY_TAB_section_employee").setVisible(false);
formContext.ui.tabs.get("SUMMARY_TAB").sections.get("SUMMARY_TAB_section_partner").setVisible(true);
formContext.ui.tabs.get("SUMMARY_TAB").sections.get("SUMMARY_TAB_section_client").setVisible(false);
break;
case 3: // Client
formContext.ui.tabs.get("SUMMARY_TAB").sections.get("SUMMARY_TAB_section_employee").setVisible(false);
formContext.ui.tabs.get("SUMMARY_TAB").sections.get("SUMMARY_TAB_section_partner").setVisible(false);
formContext.ui.tabs.get("SUMMARY_TAB").sections.get("SUMMARY_TAB_section_client").setVisible(true);
break;
default:
formContext.ui.tabs.get("SUMMARY_TAB").sections.get("SUMMARY_TAB_section_employee").setVisible(false);
formContext.ui.tabs.get("SUMMARY_TAB").sections.get("SUMMARY_TAB_section_partner").setVisible(false);
formContext.ui.tabs.get("SUMMARY_TAB").sections.get("SUMMARY_TAB_section_client").setVisible(false);
}
}
else {
setTimeout(showHideSectionsBasedOnQuickViewField, 10, context);
}
}
}