Skip to main content
Community site session details

Community site session details

Session Id : WEW5wyvbAwZ9OkzXLgnC/v
Power Apps - Microsoft Dataverse
Answered

Show/Hide fields in PowerApp - Model driven App

Like (0) ShareShare
ReportReport
Posted on 20 Mar 2024 15:58:29 by 34

Hello,

I am having an issue showing/hiding a field based on the selection.  I have a field name "decd_architectural" with just a Yes/No option.  If yes is selected, i wanted the "decd_architecturaldatereviewed" to show, else it should be hidden.

 

I wrote this simple JS below but its not quite working the way I want it.  If i toggle "yes", then the field appears but if i switch it back to "No", then it still remains.  

 

function showHideFields(executionContext) {

if(Xrm.Page.getAttribute("decd_architectural").getValue() == "No") {
Xrm.Page.getControl("decd_architecturaldatereviewed").setVisible(false);
}
else {
Xrm.Page.getControl("decd_architecturaldatereviewed").setVisible(true);
}
}

Categories:
  • Verified answer
    Jonathan Manrique Profile Picture
    2,682 on 20 Mar 2024 at 17:08:02
    Re: Show/Hide fields in PowerApp - Model driven App

    Hi @Marciniaktho 

     

    You are missing a condition, and it is not recommended to use xrm.page

    I share a code with you

     

    function showHideFields(executionContext) {
    // Obtén una referencia al formulario y al campo
    var formContext = executionContext.getFormContext(); // Pasa executionContext como parámetro en tu función
    var field = formContext.getAttribute("decd_architectural").getValue();
    
    if(field === "false") {
    
    // Para ocultar el campo
     formContext.getControl("decd_architecturaldatereviewed").setVisible(false);}
    
    // Para mostrar el campo
    if (field === "true"){
     formContext.getControl("decd_architecturaldatereviewed").setVisible(true);;
    }
    }

     

    It is still much easier to do it with a business rule for such a simple functionality.

     

     

     

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

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 791 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 410 Super User 2025 Season 2

#3
mmbr1606 Profile Picture

mmbr1606 275 Super User 2025 Season 2

Featured topics