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 / JS error for hiding/sh...
Power Apps
Unanswered

JS error for hiding/showing field (if/else) on model-driven app

(0) ShareShare
ReportReport
Posted on by 34

Trying to add a JS for hiding/showing fields based on condition. I'm getting an error message, even though i have the 'pass execution as first context checked and the web resource is on the 'OnLoad' of the form. Any ideas on what could be the issue?

 

If fieldNumber is null = show field 2

if fieldnumber not null, show field 1

 

 function hideshowSerialNumberFields(executionContext) {
 var formContext = executionContext.getFormContext();
 //Getting value from Number 
 var fieldNumber= formContext.getAttribute("field_number").getValue();
 //If Number = Blank, Show Serial Numbers and hide Serial Number
 if (fieldNumber === null) {
 formContext.getControl("field_1").setVisible(false);
 formContext.getControl("field_2").setVisible(true);
 }
 else {
 formContext.getControl("field_1").setVisible(true);
 formContext.getControl("field_2").setVisible(false);
 }
 }

 

brushb_0-1711054202819.png

 

Categories:
  • Ami K Profile Picture
    15,689 Super User 2024 Season 1 on at

    @brushb - the code looks fine to me.

     

    1. Are you sure you're using the correct Logical Names for field 1 and field 2?

    2. Are you sure you have entered "hideshowSerialNumberFields" into the Function text box?

     

    Amik_1-1711057672354.png

     

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 409 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 252 Most Valuable Professional

Last 30 days Overall leaderboard