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

if function help please

Hi,

I need some help with the code for my next button please.

I want to restrict navigation at this statge to only 5 approvers, 2 admins and the applicant
If the logged in user (VarUser) is not named in a 5 approver fields, they should be prompted with a message stating you are not an approver, I thought this may work for just 1 user:

If(!DataCardValue81.Selected.Email = VarUser , Notify("You cannot proceed as you are not an approver", NotificationType.Error))

As soon as I had ! under the = sign it states I'm using incompatible type

I'll need help adding the above suggestion (when someone can help me fix it) inside an already long if function on my Next buttons OnSelect:

If(VarUser = DataCardValue81.Selected.Email, Navigate(Screen1, Fade),
If(VarUser = DataCardValue65.Selected.Email, Navigate(Screen2, Fade),
If(VarUser = DataCardValue64.Selected.Email, Navigate(Screen3, Fade),
If(VarUser = DataCardValue68.Selected.Email, Navigate(Screen4, Fade),
If(VarUser = DataCardValue69.Selected.Email, Navigate(Screen5, Fade),
If(And(VarUser = "email1.uk" || VarUser = DataCardValue90_1.Selected.Email || VarUser = "email2.uk"), 
If(!IsBlank(DataCardValue81.Selected.Email), Navigate(Screen1,Fade),
If(!IsBlank(DataCardValue65.Selected.Email), Navigate(Screen2, Fade),
If(!IsBlank(DataCardValue64.Selected.Email), Navigate(Screen3, Fade),
If(!IsBlank(DataCardValue68.Selected.Email), Navigate(Screen4, Fade),
If(!IsBlank(DataCardValue69.Selected.Email), Navigate(Screen5, Fade),
Notify("No approvers have been added", NotificationType.Error)

)))))))))))

 

Thanks 

15 REPLIES 15
Highlighted
Helper V
Helper V

Re: if function help please

If(!DataCardValue81.Selected.Email = VarUser , Notify("You cannot proceed as you are not an approver", NotificationType.Error))

 

If(!(DataCardValue81.Selected.Email = VarUser), ...

 

 

! means the opposite from a Boolean value. And a email is not a Boolean-value. It is a text. 

Highlighted
Super User
Super User

Re: if function help please

Hi!

 

I see you've raised the bottom half of this question twice?

 

I can answer your question around the ! symbol logic:

 

You are saying with the logic portion of this formula:

If(!DataCardValue81.Selected.Email = VarUser , Notify("You cannot proceed as you are not an approver", NotificationType.Error))

(!DataCardValue81.Selected.Email) = VarUser

which is

(false) = VarUser

This is why they are not showing as compatible, left side is a Boolean and right side is your User/UserEmail variable.

 

What you should do is think about sectioning off the logic with brackets like this:

If(
   !(DataCardValue81.Selected.Email = VarUser),
   Notify("You cannot proceed as you are not an approver", NotificationType.Error)
)

 

I have attempted to answer your other question in your other post, and you'll need to go and try it and see what you can come up with from that, then come back to us again if you get stuck,

 

Cheers,

ManCat


@iAm_ManCat

Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!


Thanks!
You and everyone else in the community make it the awesome and welcoming place it is, keep your questions coming and make sure to 'like' anything that makes you 'Appy
Sancho Harker, MVP


Highlighted
Helper V
Helper V

Re: if function help please

And another tip:

 

you don’t have to create a if inside a if-function. If has 2 different syntax depending on the number of arguments. 

 

if(

  ValueToTest,
  TruePart,

  Value2ToTest,

  TrueForTest2Part,

  DefaultPart

)

 

 

or use the Switch-function. 

  

Highlighted
Community Support
Community Support

Re: if function help please

Hi @G99 ,

Do you want to navigate to different screens based on the 5 approvers, 2 admins and one applicant?

 

For your first question, the ! Operator means the opposite from a Boolean value, which is equivalent to the Not function. You may need to modify your formula as below:

If(
   DataCardValue81.Selected.Email <> VarUser , 
   Notify("You cannot proceed as you are not an approver", NotificationType.Error)
)

or

If(
   !(DataCardValue81.Selected.Email = VarUser), 
   Notify("You cannot proceed as you are not an approver", NotificationType.Error)
)

Normally, the ! operator is applied to a Boolean value or expression, rather than a Text value as you mentioned.

 

I have made a test on my side, please take a try with the following workaround:

Set the OnSelect property of the "Next" button to following:

If(
   VarUser = DataCardValue81.Selected.Email || VarUser = DataCardValue65.Selected.Email || VarUser = DataCardValue64.Selected.Email || VarUser = DataCardValue68.Selected.Email || VarUser = DataCardValue69.Selected.Email,
   Navigate(
            If(
                VarUser = DataCardValue81.Selected.Email, Screen1,
                VarUser = DataCardValue65.Selected.Email, Screen2,
                VarUser = DataCardValue64.Selected.Email, Screen3,
                VarUser = DataCardValue68.Selected.Email, Screen4,
                VarUser = DataCardValue69.Selected.Email, Screen5
            )
   ),
   VarUser = "email1.uk" || VarUser = DataCardValue90_1.Selected.Email || VarUser = "email2.uk",
   If(
      !IsBlank(DataCardValue81.Selected.Email), Navigate(Screen1,Fade),
      !IsBlank(DataCardValue65.Selected.Email), Navigate(Screen2, Fade),
      !IsBlank(DataCardValue64.Selected.Email), Navigate(Screen3, Fade),
      !IsBlank(DataCardValue68.Selected.Email), Navigate(Screen4, Fade),
      !IsBlank(DataCardValue69.Selected.Email), Navigate(Screen5, Fade)
   ),
   Notify("You cannot proceed as you are not an approver", NotificationType.Error)
)

 

Please consider take a try with above solution, then check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
Post Partisan
Post Partisan

Re: if function help please

@iAm_ManCat @max81 

 

Thank you both, I understand where I was going wrong with the ! symbol.

 

I've attempted to place the correctly typed syntax, and while testing in design mode, even though this condition is the last one I have placed, it seems to trigger the message you are not an approver, even though I am an admin. 
I will probably need to spend some time on this to get it to function

Highlighted
Post Partisan
Post Partisan

Re: if function help please

@max81 

 

Thanks for this, How can I learn about If statements and just functions, I've come across many videos but they haven't been structured in a way one can learn, are you aware of any resources which would help me?

Highlighted
Helper V
Helper V

Re: if function help please

Highlighted
Community Support
Community Support

Re: if function help please

Hi @G99 ,

Have you taken a try with the solution I provided above?

 

Based on the needs that you mentioned, I think the If formula I provided above could achieve your needs. Please take a try with it, check if it could help in your scenario.

 

More details about the If function in PowerApps canvas app, please check the following article:

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-if#syntax

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
Post Partisan
Post Partisan

Re: if function help please

@v-xida-msft 

Apologies for the delayed response,

 

Thanks for the detailed response.

I needed 2 notifications to appear, depending on the scenario

The first is if the admin has not entered at least 1 approver, no one can proceed to the next screen not even the admin:

Notify("No approvers have been added", NotificationType.Error)

But the 2nd statement will trigger when there are approvers listed, but the person logged in is not a named approver or they are not the admin...

 

I think that's where I was struggling with getting this extra notify  statement put in.

Helpful resources

Announcements
Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

secondImage

Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

secondImage

Super Users Coming in August

We are excited for the next Super User season.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (6,045)