I have an evaluation app. I was assisted by a user here in building it and since its taken off. I am having some permission issues.
Powerapps "on start"
I set variables, collections and filter data based on the user's role (tabs 1-4 super) 1-5 (admin)
Set(
gblAdmin,
LookUp(
'Control Admin List',
Title = User().Email
).Role = "Admin"
);
Set(
gblSuper,
LookUp(
'Control Admin List',
Title = User().Email
).Role = "Supervisor"
);
ClearCollect(
colTabs,
Table(
If(
Or(
gblAdmin,
gblSuper
),
{
Value: 1,
Item: "Safety"
}
),
{
Value: 2,
Item: "Employee"
},
{
Value: 3,
Item: "Employee Comments"
},
{
Value: 4,
Item: "Manager Comments"
},
If(
gblAdmin,
{
Value: 5,
Item: "HR Functions"
}
)
)
);
If(
gblSuper,
ClearCollect(
colDirectReports,
Filter(
'Employee Evaluations',
DirectSupervisor1.Email = User().Email
)
),
ClearCollect(
colDirectReports,
'Employee Evaluations'
)
)
this results in an error and all data disappears.
Attempting to lock this down further by forcing the "super" to only see entries based on the collection of direct reports defined.
- This code is checking if the user has the role of Supervisor (gblSuper is true).
- If the user is a Supervisor, it clears and collects data into colDirectReports by filtering the 'Employee Evaluations' based on the condition DirectSupervisor1.Email = User().Email.
- If the user is not a Supervisor, it clears and collects data into colDirectReports directly from 'Employee Evaluations'.
The app still writes the correct data to the sharepoint repo, but this section is not working and the defined "super"'s can still view entries in which are not their "direct reports"
There is a gallery that displays this information called galNames. Its "item" property is
With(
{
wData: Filter(
Sort(
'Employee Evaluations',
'Todays Date',
SortOrder.Descending
),
(Len(cbFindNameI.Selected.Value) = 0 || 'Employee Name' = cbFindNameI.Selected.Value)
)
},
ForAll(
Sequence(CountRows(wData)),
Patch(
Index(
wData,
Value
),
{RowNo: Value}
)
)
)
This code performs a series of operations on a collection named 'Employee Evaluations'. Here's what each part does:
With({...}): This function allows you to create a temporary context or scope in which you define variables. In this case, it creates a variable wData that holds the result of a series of operations.
wData: Filter(...): Within the With function, a variable wData is created. It is assigned the result of filtering the 'Employee Evaluations' collection.
Filter(...): This function filters a collection based on a given condition. In this case, it filters 'Employee Evaluations'. The filtering condition is defined by the condition inside the Filter function.
Sort(...): This function sorts a collection based on a specified field and sort order. In this case, it sorts 'Employee Evaluations' by the field 'Todays Date' in descending order.
ForAll(...): This function iterates over a sequence of numbers generated by Sequence(CountRows(wData)). It iterates CountRows(wData) times, where wData is the filtered and sorted collection. Each iteration generates a value Value starting from 1.
Patch(...): This function is used to update one or more properties of a record in a collection. It is applied to the item at index Value in the wData collection.
Index(...): This function retrieves an item from a collection at a specified index. In this case, it retrieves the item at index Value from the wData collection.
{RowNo: Value}: This is the data that will be patched into the record. It assigns the property RowNo with the value of Value.
In summary, this code sorts and filters the 'Employee Evaluations' collection based on certain conditions (involving the cbFindNameI.Selected.Value), and then iterates over the filtered data to apply a patch operation, updating the RowNo property of each record with the corresponding iteration value.
I've tried this on the gallery "item'
If(
CountRows(
Filter(
'Employee Evaluations',
DirectSupervisor1.Email = User().Email
)
) > 0 &&
(gblAdmin || gblSuper),
With(
{
wData: Filter(
Sort(
Filter(
'Employee Evaluations',
DirectSupervisor1.Email = User().Email
),
'Todays Date',
SortOrder.Descending
),
(Len(cbFindNameI.Selected.Value) = 0 || 'Employee Name' = cbFindNameI.Selected.Value)
)
},
ForAll(
Sequence(CountRows(wData)),
Patch(
Index(
wData,
Value
),
{RowNo: Value}
)
)
)
)
Results in an error - unable to retrieve data