Hi everyone,
I have an application that is known as Visitor Management which is used to track the number of visitors and employees (if they forget their ID card) their in-time and out-time. So the first iteration is done and now we are second iteration wherein we have two roles: Super Admin and Admin. The Super Admin can do the following:
1. They can create new locations
2. Allocate admins to locations.
And Admins can only view the data for the location they have been assigned to, (and Super Admins can view all the data no restriction)
So to satisfy the above requirement I have created two lists:
1. To store new locations (called as LocationsSuperAdmin)
2. Second list to store the admin details (allocated by super admins)
(For Administrator have made use of Person type column and Location single line of text)
In Power Apps:
On App: I have created a variable wherein I have provided my email as super admin (for testing purpose)
The Location overview screen:
To add new locations:
If(
IsBlank(LookUp(LocationsSuperAdmin_VM, Lower(Title) = Lower(LocationInputText.Text))),
Patch(
LocationsSuperAdmin_VM,
Defaults(LocationsSuperAdmin_VM),
{
Title: LocationInputText.Text
}
),
Notify("Location already exists. Please enter a new location.", NotificationType.Error)
);
Reset(LocationInputText);
Pop-up screen for adding new locations:
For allocating new admins:
If
(
formAdminCreationPopup.Mode = 1,
//When creating new records
If(
IsBlank(
LookUp(
AdminList_VM,
Administrator.DisplayName = DataCardValue5_2.Selected.DisplayName
)
),
SubmitForm(formAdminCreationPopup),
Notify("Admin for this location already exists, please try for another location!",NotificationType.Error)
),
//Updating an existing record:
SubmitForm(formAdminCreationPopup)
For Admins created a login screen wherein they enter password (it will be provided to them) and while they submit the details I am capturing their info in a variable like:
I have another list that keeps track of the individuals (whether they are visitors or employees)
So in Power Apps I have used the following expression wherein is the user is super admin they can see all the data and if they are an admin then they can only view the data for the location that they have been assigned
If(User().Email = nfSuperUserEmail,
//User is Super Admin
Sort(
If(
varsearch,
Filter(
AddColumns(
Filter(
Visitors,
'User Type'.Value = varTab
),
Name1,
If(
'User Type'.Value = "Visitor",
LookUp('Visitors(S)', ID = UserID).Title,
LookUp(Employees, ID = UserID).Title
)
),
InTime >= If(
Not IsBlank(DateValue1.SelectedDate),
DateValue1.SelectedDate + Time(Value(HourValue1.Selected.Value), Value(MinuteValue1.Selected.Value), 0)
) || DateValue1.SelectedDate = Blank(),
OutTime <= If(
Not IsBlank(DateValue1_1.SelectedDate),
DateValue1_1.SelectedDate + Time(Value(HourValue1_1.Selected.Value), Value(MinuteValue1_1.Selected.Value), 0)
) || DateValue1_1.SelectedDate = Blank(),
StartsWith(Location, TextInput_Title_10.Text) || TextInput_Title_10.Text = Blank(),
StartsWith(Name1, TextInput_Title_9.Text) || TextInput_Title_9.Text = Blank(),
StartsWith(VisitorIDCardNumber, TextInput_Title_11.Text) || TextInput_Title_11.Text = Blank()
),
Switch(
varvisitorspopup,
"Total",
AddColumns(
Filter(
Visitors,
'User Type'.Value = varTab
),
Name1,
If(
'User Type'.Value = "Visitor",
LookUp('Visitors(S)', ID = UserID).Title,
LookUp(Employees, ID = UserID).Title
)
),
"Today",
Filter(
AddColumns(
Filter(
Visitors,
'User Type'.Value = varTab
),
Name1,
If(
'User Type'.Value = "Visitor",
LookUp('Visitors(S)', ID = UserID).Title,
LookUp(Employees, ID = UserID).Title
)
),
IsToday(Created)
),
"Office",
Filter(
AddColumns(
Filter(
Visitors,
'User Type'.Value = varTab
),
Name1,
If(
'User Type'.Value = "Visitor",
LookUp('Visitors(S)', ID = UserID).Title,
LookUp(Employees, ID = UserID).Title
)
),
IsBlank(OutTime)
)
)
),
Created,
SortOrder.Descending
),
//User is Admin
Sort(
If(
varsearch,
Filter(
AddColumns(
Filter(
Visitors,
'User Type'.Value = varTab
),
Name1,
If(
'User Type'.Value = "Visitor",
LookUp(
'Visitors(S)',
ID = UserID
).Title,
LookUp(
Employees,
ID = UserID
).Title
)
),
InTime >= If(
Not IsBlank(DateValue1.SelectedDate),
DateValue1.SelectedDate + Time(
Value(HourValue1.Selected.Value),
Value(MinuteValue1.Selected.Value),
0
)
) || DateValue1.SelectedDate = Blank(),
OutTime <= If(
Not IsBlank(DateValue1_1.SelectedDate),
DateValue1_1.SelectedDate + Time(
Value(HourValue1_1.Selected.Value),
Value(MinuteValue1_1.Selected.Value),
0
)
) || DateValue1_1.SelectedDate = Blank(),
StartsWith(
Location,
TextInput_Title_10.Text
) || TextInput_Title_10.Text = Blank(),
StartsWith(
Name1,
TextInput_Title_9.Text
) || TextInput_Title_9.Text = Blank(),
StartsWith(
VisitorIDCardNumber,
TextInput_Title_11.Text
) || TextInput_Title_11.Text = Blank(),
varLocation.Location = Location // New filter for the logged-in user's location
),
Switch(
varvisitorspopup,
"Total",
AddColumns(
Filter(
Visitors,
'User Type'.Value = varTab,
varLocation.Location = Location // New filter for the logged-in user's location
),
Name1,
If(
'User Type'.Value = "Visitor",
LookUp(
'Visitors(S)',
ID = UserID
).Title,
LookUp(
Employees,
ID = UserID
).Title
)
),
"Today",
Filter(
AddColumns(
Filter(
Visitors,
'User Type'.Value = varTab,
varLocation.Location = Location // New filter for the logged-in user's location
),
Name1,
If(
'User Type'.Value = "Visitor",
LookUp(
'Visitors(S)',
ID = UserID
).Title,
LookUp(
Employees,
ID = UserID
).Title
)
),
IsToday(Created)
),
"Office",
Filter(
AddColumns(
Filter(
Visitors,
'User Type'.Value = varTab,
varLocation.Location= Location // New filter for the logged-in user's location
),
Name1,
If(
'User Type'.Value = "Visitor",
LookUp(
'Visitors(S)',
ID = UserID
).Title,
LookUp(
Employees,
ID = UserID
).Title
)
),
IsBlank(OutTime)
)
)
),
Created,
SortOrder.Descending
)
)
(So the above screenshot shows the information that Akshat who is been assigned admin for Hyderabad location can see in Power Apps)
And for some cards that display counts like Total employees:
So now what I have done in Power Apps using filters I want to replicate that on SharePoint side as well. The reason being for admins to use this application we need to share the app with them which in turn means we need to provide the List access while sharing the application. So even if in Power Apps a individual that is being assigned as admin for a location can only view the data for that location, if they navigate to SharePoint they can see all the data which is what I want to avoid and they should only be able to see the data for the location that they have been assigned to (in the AdminList_VM)
Like if Akshat who is one of the admin allocated as Admin for Hyderabad location he should only be able to view records where Location is Hyderabad (employees that are from Hyderabad), irrespective of the location that is currently working in (that means if Akshat Location in his Office365 is USA then it should not show the USA records instead show the records based on the location shown in the AdminList_VM Sharepoint list)
So for this I needed some advice on how to proceed to achieve this, so if you guys have any inputs to contribute please reply on this query post.
Regards,
Sidhant.