Loading...

ACCESS FIELDS OF QUICK VIEW FORM THROUGH JAVASCRIPT IN DYNAMICS 365

ACCESS FIELDS OF QUICK VIEW FORM THROUGH JAVASCRIPT IN DYNAMICS 365

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.

For the sake of this post, we will work with a contact quick view form control on the account form.

Based on the primary contact Relationship Type field, a specific section on the account form will be displayed.
  1. Relationship Type field of the contact = Employee => Employee section on the account form will be displayed
    Quick view form 1

  2. Relationship Type field of the contact = Partner => Partner section on the account form will be displayed
    Quick view form 2

  3. Relationship Type field of the contact = Client => Client section on the account form will be displayed
    Quick view form 3

  4. 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);
    }
    }
    }


Hope This Helps!
Learn more
Author image
Dynamics 365 Education and Knowledge

Share post:

Related

Stay up to date with latest Microsoft Dynamics 365 and Power Platform news!
* Yes, I agree to the privacy policy