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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Show/Hide fields in Po...
Power Apps
Answered

Show/Hide fields in PowerApp - Model driven App

(0) ShareShare
ReportReport
Posted on by 39

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

I have the same question (0)
  • Verified answer
    Jonathan Manrique Profile Picture
    2,695 on at

    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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 519 Most Valuable Professional

#2
11manish Profile Picture

11manish 489

#3
Haque Profile Picture

Haque 327

Last 30 days Overall leaderboard