Hi everyone,
I was working on a requirement which is as follows:
We have an application built to track visitors and employees (& their assets). For visitors to grant them temporary access card they need to fill in the information and in case of employees if they forget their ID card they need to fill in the required details, once done then only they are issued a temporary card for that day.
Now this application is deployed at one location (Pune) and we are planning to expand the same to other locations (Germany, Chennai), so for that we were thinking of having two roles: SuperAdmin and Admin. SuperAdmin will have all the access (of the data) and they can assign admins for locations. Whereas admins can only create entries and view entries only for the location for which they have been assigned to (by superadmin)
Example:
There 50 records created with Location: Pune and 78 with Germany location. And Rajesh is been assigned as Admin for Pune location so he can only view Pune location records only not other location.
So to do that I thought of retrieving all the data from Office365 connector and store it in a collection for which I have made use of following expression:
Set(varSkip, 0); // Initialize a variable for pagination
// Loop to get all users
Collect(Office365UsersCollection, Office365Users.SearchUser({searchTerm: "", top: 999, skip: varSkip}));
// Create a collection for pagination
ClearCollect(Pagination, {Value: 0}, {Value: 999}, {Value: 1998}, {Value: 2997}); // Add more items if you have more than 4000 users
// Use ForAll to get all users
ForAll(Pagination,
Collect(Office365UsersCollection, Office365Users.SearchUser({searchTerm: "", top: 999, skip: Value}))
);
//To get only Active users:
ClearCollect (
ActiveUsers,
Filter (
Office365UsersCollection,
AccountEnabled = true && !IsBlank(OfficeLocation)
//Only retreiving ActiveUsers (AccountEnabled = true) && avoiding external users for whom location is blank so have used !IsBlank(OfficeLocation)
)
)
//To get unique location values:
ClearCollect(uniqueLocations,Distinct(ActiveUsers,OfficeLocation))
Now based on selection (Location dropdown selection made in drop down) I need to show only users with that particular location (OfficeLocation), so superadmin selects : Pune then the Person type choice drop-down should only show employees with Pune location.
For that on the On-Change of thee location drop-down I used the following
ClearCollect(locationsBasedUsers, Filter(ActiveUsers,OfficeLocation=DataCardValue15.Selected.Value))
//DataCardValue15.Selected.Value: Refers to the location drop-down
It gives me the results but I have observed the collection containing few duplicates and when I tried to use the collection for Items property of the drop-down like:
Choices(locationsBasedUsers,DisplayName) or Choices(locationsBasedUsers.DisplayName)
It gave an error.
Name isn't valid. '{0}' isn't recognized (Error)
So I used: locationsBasedUsers.DisplayName, but here the issue was that I was only able to get few set of records in the dropdown (like 30 odd records that were incomplete the selected location had more number of records).
So my question was is there any better way to do it then what I have done or how can I improve my existing structure.
Regards,
Sidhant.