cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Post Patron
Post Patron

IF(LEN()) not working as expected

Hi All,

I am trying to customize a form from an SPO list, since Microsoft in their infinite wisdom can't format a phone number on a form, I am trying to  force the user to enter 10 digits into the form.  This should be easy enough, but for some reason it's not.

 

  1. On visible of the form I Set(Var10Digits,false)
  2. I set "OnChange to :If(Len('Phone Number')<>10,UpdateContext({Var10Digits: true }));
  3. I have a textbox and button visible when var is true
  4. I set the var back to false when button is pushed

Simple enough solution?

I get the textbox and button no matter what I put in the column.  Why would the Var be set to true even when there are 10 digits? 

I tried every way I can think of. 

Am I doing this in the wrong place?  

 

Any help would be greatly appreciated!

TIA,

Joe

5 REPLIES 5
Highlighted
Super User III
Super User III

Re: IF(LEN()) not working as expected

...deleted post...

Highlighted
Post Patron
Post Patron

Re: IF(LEN()) not working as expected

@mdevaney ,

Did you try to post something? 🙂

Your response is blank 

 

Highlighted
Super User III
Super User III

Re: IF(LEN()) not working as expected

@joef 

My recommendation here would be not to rely on a context variable.  Instead I would build a validation inside the textbox and buttons to check the length.

 

Put this code in the Visible property of both your text box and button

Len(PhoneNumber.Text)=10

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

Highlighted
Post Patron
Post Patron

Re: IF(LEN()) not working as expected

hi @mdevaney ,

Thanks for the response...

Good thought, but when the form opens so does my error message saying to enter 10 digits. 

Phone is not required (and the business doesn't want it to) so I can't have the box there until they mess up the entry of 10 digits..

That's the reason for checking Len() on change.

 

Thanks again,

Joe

Highlighted
Super User III
Super User III

Re: IF(LEN()) not working as expected

@joef 

Good to know lol.  Can’t blame a guy for taking the simplest path forward when solving a problem 😉

 

The reason for your issue is you have used both SET and UPDATECONTEXT for the same variable.  This is not allowed in PowerApps; you must use one or the other.  See my example below.


Set(Var10Digits,false);

 

:If(Len('Phone Number' <>10, Set({Var10Digits: true }))

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Find your favorite faces from the community presenting at the Power Platform Community Conference!

Watch Now

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (5,105)