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

OnVisible Incomplete Collection : Doesn't Populate with User Check

When my app opens I'm trying to check to see if the user has used the app before. In my data source I've created a table called 'Users' with a couple attributes. When I run a ClearCollect for that table in OnVisible, the collection populates just fine. When I add the following code that checks the collection for the current user the collection is incomplete.

 

ClearCollect(XUsers,'[dbo].[Users]');
If(User().FullName <> LookUp(XUsers,UserName = User().FullName,UserName), Patch('[dbo].[Users]',{GUID: Text(GUID()), UserName: User().FullName, DateAdded: Now(), Administrator: 0, LastLogin: Now()}
));

 

 

If I check the collection I only see two data fields getting filled. (See attachment)

1 ACCEPTED SOLUTION

Accepted Solutions
RobDin
Frequent Visitor

I found a solution to this. If I only add the UserName field (the only field I'm checking against) to my XUsers collection it works every time. 

ClearCollect(XUsers,Distinct('[dbo].[Users]',UserName));

 

I used Distinct to avoid the possibility of a duplicate during testing.

View solution in original post

4 REPLIES 4
ZabiBabar
Continued Contributor
Continued Contributor

Try this instead:

ClearCollect(XUsers,'[dbo].[Users]'); Set(currentUserName, User().FullName);
If(IsEmpty(LookUp(XUsers, UserName = currentUserName)), Patch('[dbo].[Users]',{GUID: Text(GUID()), UserName: currentUserName, DateAdded: Now(), Administrator: 0, LastLogin: Now()}
));

 

timl
Super User
Super User

Hi @RobDin 

The most likely cause of this is that you have the 'explicit column selection' setting enabled. Can you try disabling this if you have it set?

 

image.png

 

RobDin
Frequent Visitor

Thank you for the suggestions. I tried both and it didn't remedy the problem. 

As an experiment I removed the whole If statement from OnVisible and the collection had the same issue. So I'm thinking my ClearCollect is having a problem getting data from my Azure SQL Server database.

RobDin
Frequent Visitor

I found a solution to this. If I only add the UserName field (the only field I'm checking against) to my XUsers collection it works every time. 

ClearCollect(XUsers,Distinct('[dbo].[Users]',UserName));

 

I used Distinct to avoid the possibility of a duplicate during testing.

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (4,003)