web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested Answer

PowerApps Portal Show Section based on Choice

(0) ShareShare
ReportReport
Posted on by 90

Good Day. Thank you for your interest.

We have a business requirement where where we want to display a Section on a Form depending on the drop down selection the customer makes. In our scenario, It is a Student Application form, customer can apply for a single student, dual enrollment or triple. So we want to be able to display one or more sections on the portal form depending on customers selection. We have successfully implemented this with fields but is it possible to do so with an entire section on the a form??

The choice column is highlighted below: logical name: "new_studentsiblingsapplying"

The student information fields are named the same way except that the logical name for is each is incremented by numerical digits. 

Portal-Student-Siblings.PNG

Any ideas on how accomplish this would be greatly appreciated. Thank you again

Best Regards,

Sunny

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    Hi Sunny21, 

    Go to Settings > Customizations > Customize the system > entities  > Opportunity > Fields:

    --881990000 is value of the single student option for the "students siblings applying" field.

    pastedimage1646876572288v1.png

    Then I roughly recreated your scenario:

    1.Tab and sessions name

    pastedimage1646876666225v2.png

    pastedimage1646876885205v3.png

    2.Code:

    function showOrHideSection(executionContext) {
        var formContext = executionContext.getFormContext();
    
        var studentSiblingsApplying = formContext.getAttribute("custom_studentsiblingsapplying").getValue();//replace your field name new_studentsiblingsapplying
    
        var tabObj = formContext.ui.tabs.get("General_Information");//Replace your tab name
        var sectionObj2 = tabObj.sections.get("General_Information_section_2");//Replace your section2 name
        var sectionObj3 = tabObj.sections.get("General_Information_section_3");//Replace your section3 name
    
        if (studentSiblingsApplying != null && studentSiblingsApplying == 881990000) //replace your field 'single student' option1 value
        {
            sectionObj2.setVisible(false);
            sectionObj3.setVisible(false);
    
        }
        else if (studentSiblingsApplying != null && studentSiblingsApplying == 881990001)//dual students option value
        {
            sectionObj2.setVisible(true);
            sectionObj3.setVisible(false);
        }
        else {
            sectionObj2.setVisible(true);
            sectionObj3.setVisible(true);
        }
    }

    3.Add js to field OnChange event:

    (1)Double-click the field to open one dialog to add new:

    pastedimage1646877433030v4.png

    (2)Create new web resource:

    pastedimage1646877456445v5.pngpastedimage1646877540223v6.png

    (3)Add the new created web resource:

    pastedimage1646878382921v7.pngpastedimage1646878676407v8.png

    (4)Save and publish.

    4.Test

    pastedimage1646880507009v10.png

  • Sunny21 Profile Picture
    90 on at

    Thank You Leah. This is very helpful.

    *sorry this may be a novice question but what is the field value? and how do I find it?

    More importantly the "students siblings applying" is a choice field with 3 options: (single student, dual students, and triple). As you can see in my original post, there are 3 sections, one for each student. How do I adjust the code to show sections corresponding to the choice selection. For example, if the customer selects only (single) student, then I would need sections 2 and 3 hidden. Likewise if the customer chooses  (dual) students, then I would need only sections 1 and 2 to be shown but section 3 hidden? Thank you again. your help is very much appreciated

    Regards,

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi Sunny21,

    Yes, you can display one or more sections based on one field value through js code.

    1.Functions:

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

    Syntax to get the section object:

    var tabObj = formContext.ui.tabs.get(arg);

    var sectionObj = tabObj.sections.get(arg);

    Syntax to show/hide section:

    sectionObj.setVisible(bool);

    2.Get name of tab and section:

    Go to Settings > Customizations > Customize the system > entities  > Opportunity > Forms:

    pastedimage1646793580725v2.pngpastedimage1646793619176v3.png

    3.Code

    function showOrHideSection(executionContext) {
        var formContext = executionContext.getFormContext();
    
        var studentSiblingsApplying = formContext.getAttribute("new_studentsiblingsapplying").getValue();
    
        var tabObj = formContext.ui.tabs.get("Summary");//Replace your tab name
        var sectionObj = tabObj.sections.get("Summary_CadenceWidget");//Replace your section name
    
        if (studentSiblingsApplying != null && studentSiblingsApplying == 267460000) //replace your field value
        {
            //show the section
            sectionObj.setVisible(true);
        }
        else {
            //hide the section
            sectionObj.setVisible(false);
        }
    }

    Note: how to call an event on OnChange of the field:

    How to use Javascript on Dynamics CRM 2011/2013/2015 form | Customer and Employee Engagement Blog (c5insight.com)

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

News and Announcements

Season of Giving Solutions is Here!

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
iampranjal Profile Picture

iampranjal 66

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 51 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 40 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans