cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SukieP
Advocate III
Advocate III

If statement should evaluate false but evaluates true

//If (

(
     (
          Gallery2.Selected.RequestStatus = "Not Submitted" //false
          And
          (

               Lower(User().Email) = Lower(Gallery2.Selected.DeanVPEmail) //true
               Or
               Gallery2.Selected.'Created By'.Email = User().Email //true
          )

     )
     Or
     (
          Lower(User().Email) = Lower(Gallery2.Selected.DeanVPEmail) //true
          And
          Left(Gallery2.Selected.RequestStatus, 14) = "Submit Pending" //false

     )
)

 

I'm using this statement in an If to determine whether form should be edit or view.  When I'm in formula bar, I can highlight each of the parts and I get the true or false indicated in the comments.  But the whole statement evaluates to TRUE in PowerApps.  And both sides of the "Or" evaluate to TRUE, even though the Gallery2.Selected.RequestStatus statements are false.  ???

2 ACCEPTED SOLUTIONS

Accepted Solutions
RandyHayes
Super User
Super User

@SukieP 

One of the things to get in the habit of doing is forcing the order of precedence that you want to apply to your logic.

Sometimes a statement like:

   Lower(User().Email) = Lower(Gallery2.Selected.DeanVPEmail) && false

PowerApps will evaluate it as Lower(User().Email) = Lower(Gallery2.Selected.DeanVPEmail) && false

Noting in blue how in the first is what you expect to be evaluate and the second, how PowerApps does the eval.

 

Also...sometimes the formula editor WILL fool you!!  

 

Let's revisit the formula and change to: 

Select(Parent);

Set(varRecord, ThisItem);
Set(varTab, "Start");
Set(varFormMode,
    If(
       (
         (
           (Lower(User().Email) = Lower(Gallery2.Selected.DeanVPEmail)) &&
            StartsWith(Gallery2.Selected.RequestStatus, "Submit Pending")
         )
         ||
         (
           StartsWith(Gallery2.Selected.RequestStatus, "Not Submitted") &&
           (
             (Lower(User().Email) = Lower(Gallery2.Selected.DeanVPEmail)) ||
              Gallery2.Selected.'Created By'.Email = User().Email
           )
         )
       ),
        FormMode.Edit,
        FormMode.View
    )
);

Set(varTimerGo, varFormMode = FormMode.Edit);
Navigate(ScreenForm, ScreenTransition.UnCoverRight)

IN this one I have stated the exact order of evaluation for the logic.  Also, broke it out to fit more of your requirement (even though that can be simplified a bit - but let's not confuse that for the moment).

 

See where that takes you.

 

If the editor still appears to show the wrong value, then put a label on your screen and set the Text property to:

(
   (
      (Lower(User().Email) = Lower(Gallery2.Selected.DeanVPEmail)) &&
       StartsWith(Gallery2.Selected.RequestStatus, "Submit Pending")
   )
   ||
   (
       StartsWith(Gallery2.Selected.RequestStatus, "Not Submitted") &&
       (
          (Lower(User().Email) = Lower(Gallery2.Selected.DeanVPEmail)) ||
           Gallery2.Selected.'Created By'.Email = User().Email
       )
    )
)
        

This will show the real result of the eval in the label.  It would be more accurate than the editor can be.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

RandyHayes
Super User
Super User

@SukieP 

Very good - it does lie sometimes!

 

However you don't need any of the OnVisible formulas you have.  As mentioned in the prior response, your DefaultMode property on the forms should be set to varFormMode.  The form will automatically change to that mode when the variable changes.  You don't need to issue a function (ViewForm, EditForm) for each one when using this method.

Keep it simple!  Remember - You're writing Excel formulas, not code!

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

8 REPLIES 8
RandyHayes
Super User
Super User

@SukieP 

I'm getting false from the formula!  Is there more to your formula than what you posted?  Perhaps there is an issue there?

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
SukieP
Advocate III
Advocate III

Thank you Randy!  Here's whole formula:

 

Select(Parent);
If(
(
(
Gallery2.Selected.RequestStatus = "Not Submitted" //false
And
(
Lower(User().Email) = Lower(Gallery2.Selected.DeanVPEmail) //true
Or
Gallery2.Selected.'Created By'.Email = User().Email //true

)
)
Or
(
Lower(User().Email) = Lower(Gallery2.Selected.DeanVPEmail) //true
And
Left(Gallery2.Selected.RequestStatus, 14) = "Submit Pending" //false

)
),
EditForm(Form1);
EditForm(Form0);
EditForm(Form2);
EditForm(FormKPI);
Set(
varTimerGo,
true
);
Set(
varMode,
"Edit"
),
ViewForm(Form1);
ViewForm(Form0);
ViewForm(Form2);
ViewForm(FormKPI);
Set(
varMode,
"View"
)
);
Set(
varRecord,
ThisItem
);
Set(
varTab,
"Start"
);
If(
varMode = "Edit",
Set(
varTimerGo,
true
)
);
Navigate(
ScreenForm,
ScreenTransition.UnCoverRight
)

RandyHayes
Super User
Super User

@SukieP 

My suggestion would be this...change your OnSelect action formula to the following:

Select(Parent);

Set(varRecord, ThisItem);
Set(varTab, "Start");
Set(varFormMode,
    If(
        Lower(User().Email) = Lower(Gallery2.Selected.DeanVPEmail) &&
        (StartsWith(Gallery2.Selected.RequestStatus, "Submit Pending") ||
         Gallery2.Selected.'Created By'.Email = User().Email
        ),
        FormMode.Edit,
        FormMode.View
    )
);

Set(varTimerGo, varFormMode = FormMode.Edit);
Navigate(ScreenForm, ScreenTransition.UnCoverRight)

 

Then for the DefaultMode property of Form1, Form0, Form2, and FormKPI, set the mode to:  varFormMode

 

This will put the form into the correct mode depending on the selection made and the logic you had (altered slightly to simplify - not sure if I captured your logic properly, but it seemed like it in thought).  

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
SukieP
Advocate III
Advocate III

Thank you Thank you!  This is my first app and this kind of help is so appreciated!  Will give it a try 🙂

SukieP
Advocate III
Advocate III

Still having trouble -- had to alter Randy's suggestion a little.  The logic is

(1) form can be edited if status = Submit Pending and user is the Dean/VP, OR

(2) form can be edited it status = Not Submitted and user is either the Dean/VP or the Creator.   

 

Still getting true, so replace one of the conditions with "false" and PowerApps still says it's true.  

SukieP_1-1627333173779.png

Seems like PowerApps is lying to me.  

RandyHayes
Super User
Super User

@SukieP 

One of the things to get in the habit of doing is forcing the order of precedence that you want to apply to your logic.

Sometimes a statement like:

   Lower(User().Email) = Lower(Gallery2.Selected.DeanVPEmail) && false

PowerApps will evaluate it as Lower(User().Email) = Lower(Gallery2.Selected.DeanVPEmail) && false

Noting in blue how in the first is what you expect to be evaluate and the second, how PowerApps does the eval.

 

Also...sometimes the formula editor WILL fool you!!  

 

Let's revisit the formula and change to: 

Select(Parent);

Set(varRecord, ThisItem);
Set(varTab, "Start");
Set(varFormMode,
    If(
       (
         (
           (Lower(User().Email) = Lower(Gallery2.Selected.DeanVPEmail)) &&
            StartsWith(Gallery2.Selected.RequestStatus, "Submit Pending")
         )
         ||
         (
           StartsWith(Gallery2.Selected.RequestStatus, "Not Submitted") &&
           (
             (Lower(User().Email) = Lower(Gallery2.Selected.DeanVPEmail)) ||
              Gallery2.Selected.'Created By'.Email = User().Email
           )
         )
       ),
        FormMode.Edit,
        FormMode.View
    )
);

Set(varTimerGo, varFormMode = FormMode.Edit);
Navigate(ScreenForm, ScreenTransition.UnCoverRight)

IN this one I have stated the exact order of evaluation for the logic.  Also, broke it out to fit more of your requirement (even though that can be simplified a bit - but let's not confuse that for the moment).

 

See where that takes you.

 

If the editor still appears to show the wrong value, then put a label on your screen and set the Text property to:

(
   (
      (Lower(User().Email) = Lower(Gallery2.Selected.DeanVPEmail)) &&
       StartsWith(Gallery2.Selected.RequestStatus, "Submit Pending")
   )
   ||
   (
       StartsWith(Gallery2.Selected.RequestStatus, "Not Submitted") &&
       (
          (Lower(User().Email) = Lower(Gallery2.Selected.DeanVPEmail)) ||
           Gallery2.Selected.'Created By'.Email = User().Email
       )
    )
)
        

This will show the real result of the eval in the label.  It would be more accurate than the editor can be.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

SukieP
Advocate III
Advocate III

Thank you AGAIN.  You were right - the editor was lying.  Using a label to display the results of the IF condition gave me accurate information.  Then I was able to find my real problem:  OnVisible for the form screen was set to 

 

If(varFormMode = FormMode.New, NewForm(Form0); NewForm(Form1); NewForm(Form2); NewForm(FormKPI),

varFormMode = FormMode.Edit, EditForm(Form0); EditForm(Form1); EditForm(Form2); EditForm(FormKPI))

 

If NEEDED to be set to 

If(varFormMode = FormMode.New, NewForm(Form0); NewForm(Form1); NewForm(Form2);NewForm(FormKPI), varFormMode = FormMode.Edit, EditForm(Form0); EditForm(Form1); EditForm(Form2); EditForm(FormKPI),

ViewForm(Form0); ViewForm(Form1); ViewForm(Form2); ViewForm(FormKPI)) 

 

Finally!  Thanks again 😊

RandyHayes
Super User
Super User

@SukieP 

Very good - it does lie sometimes!

 

However you don't need any of the OnVisible formulas you have.  As mentioned in the prior response, your DefaultMode property on the forms should be set to varFormMode.  The form will automatically change to that mode when the variable changes.  You don't need to issue a function (ViewForm, EditForm) for each one when using this method.

Keep it simple!  Remember - You're writing Excel formulas, not code!

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (3,441)