top of page
Writer's pictureAndrew Gallagher

PowerApps : If I only knew!

I have been using an IF THEN ELSE statements since the day I started programming back in the late 80's. So while I was developing my latest power application I found the formatting of the IF statement can differ depending on the type of variable or the variable that is returned.


I had created a variable called EntryTypeVar, which was set by the user pressing a ADD button or a MODIFY button. If the ADD button was pressed EntryTypeVar was set to New and if the MODIFY button was pressed EntryTypeVar was set to Edit. My first IF statement on the item property of a form was determining whether the form would be in either New or Edit Mode. This was achieved with the following code. If(EntryTypeVar="New",Defaults('Leave Requests'),EntryTypeVar="Edit",tblLeaveRequests.Selected) If EntryTypeVar is New then open a new form. If EntryTypeVar is Edit then open the form using the data selected from a table.

My second IF statement on the Visible property of a label was determining whether the label would be visible or not. When I used the same format Power Apps complained of errors. If EntryTypeVar="New",dceLeaveIDLabel.Visible="False",EntryTypeVar="Edit",dceLeaveIDLabel.Visible="True"

Now my logic seemed sound, If EntryTypeVar is New set the dceLeaveIDLabel.Visible to False and EntryTypeVar is Edit set the dceLeaveIDLabel.Visible to True but what I didn't realise is that the Visible Property expects either a TRUE or FALSE value to be returned. The Visible property must either equal TRUE or FALSE.

Which means my IF statement needs to return a true or false value not set a value. So I changed my IF statement to use IsMatch to test the EntryTypeVar and return a true or false back to the Visible property. If(IsMatch(EntryTypeVar,"Edit"),true,false)

So now if EntryTypeVar equals Edit the label is visible otherwise the label cannot be seen.


7 views0 comments

Recent Posts

See All

Comments


bottom of page