cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
joef
Continued Contributor
Continued Contributor

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
mdevaney
Super User III
Super User III

...deleted post...

joef
Continued Contributor
Continued Contributor

@mdevaney ,

Did you try to post something? 🙂

Your response is blank 

 

mdevaney
Super User III
Super User III

@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."

joef
Continued Contributor
Continued Contributor

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

mdevaney
Super User III
Super User III

@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
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (17,642)