cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Leslie
Frequent Visitor

If exists, retrieve and display an item from a SharePoint list in ViewForm, if not exists, open NewForm for creation

Hello Fellow PowerApps Enthusiasts!

Caveat: I am very new to PowerApps, please excuse my ignorance. 

What I have is a PowerApp running off of two SharePoint lists. One list captures custom profile information about each app user. The first list contains a Person/Group field to capture the user's (AD object?) details. The second list holds data entry information entered by each user captured in the first list. 

What I want to do:

When a users logs into the app and clicks on a "My Profile" button:

  • check if his "profile information" already exists in the first list
    • If profile information exists, display the list item details in View mode
    • If profile information does NOT exist, prompt user to create profile details by showing new item create form for data entry

What I have tried to do:

  • LookUp( List1, User().Email = List1.Profile.Email ) - where Profile is the field name containing the Person/Group object

Fails miserably because it finds no items, even though the list has a record with my data in it. 

Is this too little or too much information? Any pointers would be helpful...

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions

Is your UPN the same as your email address? The UPN would be the user account your log in with. For most companies the UPN and Email Address but some like the company I work for are different. why this matters is because User().Email actually returns your UPN and not your email address.



--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.

View solution in original post

7 REPLIES 7
Jeff_Thorpe
Super User
Super User

I am surprised the Lookup() isn't giving you an error because of the way you are using the list name in the condition of the lookup.

Drop a label on the screen and add this formula:

IsBlank(LookUp( List1, User().Email = Profile.Email ).Profile.Email)

It will return true if the user record can't be found and false if the record can be found. This will help troubleshoot if the Lookup() is working as expected.

 



--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.

You're right @Jeff_Thorpe , dropping in a label and using the formula as you described returns true, meaning no records found. Which is surprising, because I don't quite know what is going wrong... 😥

Is your UPN the same as your email address? The UPN would be the user account your log in with. For most companies the UPN and Email Address but some like the company I work for are different. why this matters is because User().Email actually returns your UPN and not your email address.



--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.

View solution in original post

Ah! My UPN is NOT the same as my email address. Legacy quirk on our Active Directory that's been nettlesome over the years, and strikes once again. 😡

Hmmm... I wonder what options I have now to compare a logged-in user against a SharePoint "Person" column. Surely there must be some easy and obvious way to accomplish this?

 

 

 

Leslie
Frequent Visitor

OK I've got it working finally! Used Office365Users.MyProfile() instead of User(), which contained the DisplayName field enabling the app to do a successful comparison. 

 

Thank you for the hints @Jeff_Thorpe !

You can also improve your performance by putting the Office365Users.MyProfile() into a variable in the OnStart of the app or the OnVisible of the screen. By creating a variable you can you that variable through the app instead of having Office365Users called every time you need the current user's information. Now if you are only using the current user's information in the one Lookup() then you probably won't notice a difference.

Set(varUser, Office365Users.MyProfile())

LookUp( List1, varUser.mail = Profile.Email )



--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.

@Jeff_Thorpe thanks for this! The term gets called a few other times and it will certainly help with performance, and will also hopefully get rid of the pesky warning ⚠️ sign saying the line will slow down the app!

 

 

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 (1,635)