Hello,
I am fairly new to PowerApps. I have created a canvas app that will allow users to enter their shifts and have it stored in a collection. They can enter multiple entries and can view all of their specific entries before writing it to a sharepoint list. Here is where I am running into an issue. When multiple users access the app and enter their info, they will only see theirs, but can inadvertently post someone else's shift if it is in the collection.
Example:
Victor and David add two shifts to the collection at the same time. If Victor submits before David, both records get written to Sharepoint. I want Victor to only be able to submit Victor's shift if this is possible.
This is how I have my gallery wired up to filter the collection:
Filter (MyCollection, EmployeeName = varUser.FullName)
And this is how I have my submit button wired up:
ForAll(MyCollection, Patch('Sharepoint_List', Defaults('Sharepoint_List'), {Title:"Default Text",Status:"Default Text", Employee_Name:EmployeeName, Location:Location, Start_Date:StartDate, Start_Time:StartTime, End_Date:EndDate, End_Time:EndTime, Type_of_Hours:TypeofHours, 'Notes / Comments':Notes})); Clear(MyCollection); Notify("Success",Success,2000)
Any assistance would be greatly appreciated.
Thank you,
VicA26
Solved! Go to Solution.
Is your app shared by multiple people on the SAME device? You mention that you are creating a collection in your app. The collection is not shared between apps. It is only relevant to the local device. So, if someone is changing or altering values on another device, that will not impact the first app.
I am not sure if that is your concern, but your post was worked a bit like that, so I wanted to address it.
Also not entirely sure why you need a collection for what you are doing. You can simply work with the datasource in your Gallery and everything else.
As for your Patch statement, I am not sure what the values are that you are assigning to the columns in your patch. Are these coming from some form or controls? If so, they will need more information on them to work properly.
Also, your ForAll is a little backward. Too many look at the ForAll as a programming For-Loop, it is not just that, it is a function that returns a table. So, for performance, it is better to Collect(SharePointList, ForAll(yourCollection, {...values...}))
I hope this is helpful for you.
Is your app shared by multiple people on the SAME device? You mention that you are creating a collection in your app. The collection is not shared between apps. It is only relevant to the local device. So, if someone is changing or altering values on another device, that will not impact the first app.
I am not sure if that is your concern, but your post was worked a bit like that, so I wanted to address it.
Also not entirely sure why you need a collection for what you are doing. You can simply work with the datasource in your Gallery and everything else.
As for your Patch statement, I am not sure what the values are that you are assigning to the columns in your patch. Are these coming from some form or controls? If so, they will need more information on them to work properly.
Also, your ForAll is a little backward. Too many look at the ForAll as a programming For-Loop, it is not just that, it is a function that returns a table. So, for performance, it is better to Collect(SharePointList, ForAll(yourCollection, {...values...}))
I hope this is helpful for you.
Hi @VicA26
First, you want to capture the user identity when the app opens. I prefer User().Email rather than User().FullName. because variations in the user names with different cases and spaces can create confusion. You may want to do this if your current method works inconsistently. Maintaining your method, in the App property OnStart.
Set(ThisUser, Trim(Lower(User().FullName))
In your gallery, you can filter Similar to how you are doing it.
Filter (MyCollection, Trim(Lower(EmployeeName) = ThisUser))
This will filter the gallery to only show items for the logged in User.
The submit button can be simplified to
With(
{
(mycollection,{Title:"Default Text",Status:"Default Text", Employee_Name:ThisUser, Location: Location, Start_Date:StartDate, Start_Time:StartTime, End_Date:EndDate, End_Time:EndTime, Type_of_Hours:TypeofHours, 'Notes / Comments':Notes}
)
},
Collect(
SPlist, Filter(
mycollection, Employee_Name=ThisUser
)
)
The final collect, will only submit items created by the named employee to the SharePoint list.
RandyHayes,
Thank you for your response. Are you stating that if the app is used across multiple devices, the collections created will not be the same? So collection on mobile device A will not have information from mobile device B? Just to clarify.
Thank you,
VicA26
Yes, that is correct. Collections are local to the app. In fact, a Collection is really just a variable that has the ability to add or remove rows. Beyond that, it is just a variable. And just like a variable, it would only be local to the app.
Going a step beyond (to fortify your learning), a datasource is really just a variable as well...except, it has the ability to add or remove rows (like a collect), but it is also tied to the datasource as well. So, if you add or remove rows, or alter values, they are then (through the cloud) reflected in the datasource that it is pointed to.
In regard to datasources, when you start a PowerApp, a session is created in the cloud. In that session, there is a tie to the datasources you have. Your app interacts with THAT data - not directly with the datasource. Why mention this? Because this is another area of confusion for folks with multi users. If user on device A updates a record in datasourceX, then the user on device B will NOT see that change. They would need to refresh the datasource. This causes the session to dump its temporary copy of data in the session (again in the cloud) and to repopulate from the real data source. (note this is one of the reasons why PowerApps has record limits, if PowerApps had to load 10 million records on a refreshes, their cloud would crash)
So in short - toward your concern - there is nothing that is shared between devices in the app, not even the datasource changes.
I hope that is fairly clear and helpful.
Hello RandyHayes,
This is what I was looking for. Know that worked great. I also took your advice and wrote the data directly to the source then had the users pull their records to view and edit as needed.
Thank you,
VicA26
Hello Drrickyp,
Thank you for your response. I used this with another app I am working on. I don't have much experience with the With statement but after seeing your code I looked into it and it will help me out.
Thank you,
VicA26
User | Count |
---|---|
258 | |
111 | |
95 | |
48 | |
41 |