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)
Solved! Go to Solution.
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.
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()}
));
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?
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.
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.
User | Count |
---|---|
246 | |
103 | |
82 | |
49 | |
42 |