cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
milky_bar_may
Helper IV
Helper IV

User().FullName function to access screen instead of password protect

Hi PowerApps Team! 

 

I have a button that when clicked navigates to a screen with sensitive data. This screen is currently password protected.

 

Would it be possible to utilise the User().FullName function instead of password protecting? 

 

My idea was that if  User().FullName exists in a column in my sharepoint list then they can access the screen, otherwise they can't. 

 

I tried doing an if statement:

 

=if (UserFullNamelbl.Text = LookUp( UsernameDatabase, UsernameColumn = UserFullNamelbl.Text ), navigate(screen2))

 

UserFullNamelbl.Text is a lbl equal to User().FullName

 

Unfortunately PowerApps does not seem to like this code. 

 

Thanks everyone!! 

D

1 ACCEPTED SOLUTION

Accepted Solutions

OK @milky_bar_may ,

Firstly isBlank has a capital B.
You also have to make sure the second bit works

Set(
   vAuthUser,    
   LookUp(
      UsernameDatabase,
      UsernameColumn = vUserName,
      UserNameColumn
   )
);

Is your list names UsernameDatabase and your field with the user name UserNameColumn?
You can also use

Set( 
   vAuthUser, 
   LookUp(
      UsernameDatabase, 
      UsernameColumn = vUserName
   ).UserNameColumn
)

 

View solution in original post

8 REPLIES 8
WarrenBelz
Super User
Super User

Hi @milky_bar_may ,

User functions as not Delegable, so as a precaution, set a Variable at App Onstart and also see if user is in list

Set(
   vUserName,
   User().FullName
);
Set(
   vAuthUser,    
   LookUp(
      UsernameDatabase,
      UsernameColumn = vUserName
   )
) 

Then - if they are there (I am assuming this is the test you need)

If(
   !isBlank(vAuthUser),
   Navigate(screen2),
   Whatever you do for other users
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Hi @WarrenBelz 

 

Many thanks for the reply.

 

Unfortunately it did not work. 

 

I followed your instructions, putting the code in OnStart  and then on my button.

 

However when I clicked the button nothing happens. It doesn't navigate me to the second screen.

 

I am not an PowerApps expert so am definitely scratching my head and don't have alternative ideas

 

Thanks

 

D

Hi @milky_bar_may ,

The code should have returned a table, which should work, but try this using the field name in the SharePoint list. I assume the list and field names are correct.
To test, put this on a button on screen 1. Also put in a label with the Text property vAuthUser and see what is there.

Set(
   vUserName,
   User().FullName
);
Set(
   vAuthUser,    
   LookUp(
      UsernameDatabase,
      UsernameColumn = vUserName,
      UserNameColumn
   )
);
If(
   !isBlank(vAuthUser),
   Navigate(screen2),
   Notify("User is not authorised",NotificationType.Error)
)

 

Hi @WarrenBelz ,

 

Many thanks for your response. 

 

On further investigation it says '!isblank(vAuthuser)' is invocation of unknown or unsupported function.

 

 

 

 

 

 

 

Try

Set(
   vAuthUser,    
   LookUp(
      UsernameDatabase,
      UsernameColumn = vUserName
   ).UserNameColumn

OK @milky_bar_may ,

Firstly isBlank has a capital B.
You also have to make sure the second bit works

Set(
   vAuthUser,    
   LookUp(
      UsernameDatabase,
      UsernameColumn = vUserName,
      UserNameColumn
   )
);

Is your list names UsernameDatabase and your field with the user name UserNameColumn?
You can also use

Set( 
   vAuthUser, 
   LookUp(
      UsernameDatabase, 
      UsernameColumn = vUserName
   ).UserNameColumn
)

 

v-bofeng-msft
Community Support
Community Support

Hi @milky_bar_may :

Do you want to implement the following functions

  • Specific users can access the screen 2.

Can you tell me:

  • Whats UsernameColumn”‘s datatype? Text? Or?

I assume the datatype of UsernameColumn is Text.

I made a test but didnt encounter the error. Here is my solution for your reference:

Add a button and set its OnSelect property to:

 

Set(vUserName,User().FullName);   /* If you don't care whether it is delegable, you can use User().FullName directly */
If(
    !IsBlank(
        LookUp(
            UsernameDatabase,
            vUserName = UsernameColumn
        )
    ),
    Navigate(Screen2)
)

 

By the way, this item needs your attention

  • About OnStart property: After you change the OnStart property, test it by hovering over the App object in the Tree view pane, selecting the ellipsis (...) that appears, and then selecting Run OnStart.
 

 Capture.PNG

 

Best Regards,

Bof

Hi @HadynM , @WarrenBelz , @v-bofeng-msft 

 

Many thanks to you all - you were all extremely helpful and the solution now works.

 

Thanks 

 

D

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

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