Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Hiding the section on quickview form based on lookup field based on main form using javascript

Posted on by

Hi everyone, I wanted to hide the section on quickview form based on lookup field present on main form.

my code is this 

function hideAndShow(executionContext)

{

debugger

var formContext = executionContext.getFormContext();

var quickViewControl = formContext.ui.quickForms.get("Quick_Form");

var assetcode = formContext.getAttribute("pcl_field).get value();

if(quickViewControl != undefined)

{

if(quickViewControl.isLoaded())

{

if(assetcode == "Guid1")

{

quickViewControl.ui.tabs.get("tab_1").sections.get("section_1").setVisibile(true);

}

if(assetcode == "Guid2")

{

quickViewControl.ui.tabs.get("tab_1").sections.get("section_2").setVisibile(true);

}

else {

quickViewControl.ui.tabs.get("tab_1").sections.get("section_1").setVisibile(false);

}

  • Suggested answer
    Yuri ji Profile Picture
    Yuri ji on at
    RE: Hiding the section on quickview form based on lookup field based on main form using javascript

    Hi,

    The code you provided does get the section on the main form.

    However, after my testing, this code does not seem to get the section of the quick form.

    It is also true that the official file of Microsoft below does not provide a corresponding method.

    formContext.ui.quickForms (Client API reference) in model-driven apps - Power Apps | Microsoft Docs

    “getControl” in the document can only capture fields.

    pastedimage1662026609512v1.png

    You can also try hiding the fields directly.

    The example I gave controls the hiding of the “Email” field in the “Quick View Form” based on the value of the “Parent Account” field on the Account main form.

    The “Email” field is displayed only when the specified account is matched

    Please refer to my example to test it:

    1. Code.

    function hide(executionContext){
    var formContext = executionContext.getFormContext();
        var parentAccount = formContext.getAttribute("parentaccountid").getValue();
        var quickViewControl = formContext.ui.quickForms.get("QuickviewControl1662000232662");
        if(quickViewControl){
            if(parentAccount){
                var account = parentAccount[0].id;  
                if(account  == "{A56B3F4B-1BE7-E611-8101-E0071B6AF231}"){
                    quickViewControl.getControl(1).setVisible(true); 
                    // The number in “getControl” is used to select the field, in this form “Email” is the second field from zero.
                }else{
                    quickViewControl.getControl(1).setVisible(false);
                }
            }
        }
    }
    

    2. View results.

    Match to the correct account.

    pastedimage1662026797480v2.png

    Not matched to the correct account.

    pastedimage1662026809483v3.png

  • Hrithik Profile Picture
    Hrithik on at
    RE: Hiding the section on quickview form based on lookup field based on main form using javascript

    Hello Kapil, i already tried this but it is not working, i have to use lookup field to hide the sections in quickview.

  • Suggested answer
    KK-365 Profile Picture
    KK-365 1,010 on at
    RE: Hiding the section on quickview form based on lookup field based on main form using javascript

    Hello,

    Please follow the below answer link, this should solve your query:

       

    Do let me know if you face any difficulty.

    If you find this helpful, please mark it verified.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans