Can anyone help with this problem. I have a form with an attachment control for uploading photos to a sharepoint list. The user is assessing equipment in a facility and sometimes they have a terrible data connection. What happens is a connection check is made if it is connected then a SubmitForm runs. Otherwise the data is pushed into a collection where it can be viewed in an offline gallery. This data is stored via a SaveData command. Below is the code for what was mentioned above.
If(
Connection.Connected,
SubmitForm(HydronicPiping);
Navigate(BrowseGallery1,ScreenTransition.None);,
Collect(
colMyOfflineRecords,
{
Title: datEquipID.Text,
BuildingName: datBuildingName.Selected.Value,
SelectDiscipline: datSelectDiscipline.Selected.Value,
BarcodeNumber: txtBarcode.Text,
IsBarcodeRequired : datIsThereABarcode.Selected.Value,
AssessmentSubmitter: User().FullName,
Photos: galHydronicPiping.AllItems.Image2_9,
WhenCreated: Now(),
AttachPhotos: colTakePhoto,
}
);
SaveData(colMyOfflineRecords, "myOfflineRecords");
Navigate(OfflineScreen, ScreenTransition.None);
);
When the user returns to a good connection they can access the offline gallery on a separate screen and tap a button that runs the below code.
ForAll(
colMyOfflineRecords,
Patch(
USD259_Equip_Assess_DB,
Defaults(USD259_Equip_Assess_DB),
{
Title: Title,
'Building Name': {Value: BuildingName},
'Assessment Submitter': {DisplayName: AssessmentSubmitter,
Claims:"i:0#.f|membership|" & Lower(User().Email),
Department:"",
Email:"",
JobTitle:"",
Picture:""},
'Select Discipline': {Value: SelectDiscipline},
'Select Mechanical Equipment Type': {Value: EquipType},
'Barcode Number': BarcodeNumber,
'Is there a barcode': {Value:IsBarcodeRequired},
Attachments: AttachPhotos
}
)
);
How do I get the photos that are in the attachment control that is loaded into a collection for oflfine storage uploaded with the rest of the data.
To start, your formula has the ForAll backward. You are trying to use it like a ForLoop in some development language - which PowerApps is not. It is a function that returns a table of records based on your iteration table and record schema.
It is more efficient to use the function as intended and will provide better performance.
So your formula should be:
With({_usr: User()}),
Patch(USD259_Equip_Assess_DB,
ForAll(colMyOfflineRecords,
{
Title: Title,
'Building Name': {Value: BuildingName},
'Assessment Submitter':
{DisplayName: AssessmentSubmitter,
Claims:"i:0#.f|membership|" & Lower(_usr.Email),
Department:"",
Email: _usr.Email,
JobTitle:"",
Picture:""
},
'Select Discipline': {Value: SelectDiscipline},
'Select Mechanical Equipment Type': {Value: EquipType},
'Barcode Number': BarcodeNumber,
'Is there a barcode': {Value:IsBarcodeRequired}
}
)
)
)
However - for the attachments, you will need to utilize a PowerAutomate flow to store your attachments. You can ONLY submit attachments through a Form. Patch will not work. So, since you are performing a bulk patch to your datasource and not an individual submitform, you would not be able to do this.
I hope this is helpful for you.
Can you explain With({_usr: User()}),
Hi @RandyHayes,
I have used the ForAll and Patch pattern that @colbyturybury has shared multiple times and I haven't compared that with the one you shared, but just wanted to clarify that it is a format that works. That being said, I prefer
Patch(Table, collection)
In this pattern, only one data call is made whereas in the others, multiple data calls are made.
Just thought I would share my 2 cents here.
Thanks,
Hardit Bhatia
Is there a way to save all the content of a form including attachments to the local device to upload later
Yes, the ForAll used as it was in its backward way will work, it will just work inefficiently and performance will suffer from it. ForAll is a function that is used to return a table.
The thing about Patch(source, collection) is actually identical to the concept of Patch(source, ForAll(...)) In BOTH cases, you are providing a table to Patch...this is highly efficient!
The With statement is used to perform the User() function only once in the formula. It is relatively expensive in terms of performance, so issuing it many times is a waste of time and will slow down the process. Doing it only once is all that is needed.
Yes, you can store the attachments to the device and then later recall them to upload to a flow.
When pasting your code in the With statement errors out.
Is there a way to save the data to the device then reload it into a form so the user can sync when they have a data connection again?
Sorry - typo in the formula. Should be:
With({_usr: User()},
Patch(USD259_Equip_Assess_DB,
ForAll(colMyOfflineRecords,
{
Title: Title,
'Building Name': {Value: BuildingName},
'Assessment Submitter':
{DisplayName: AssessmentSubmitter,
Claims:"i:0#.f|membership|" & Lower(_usr.Email),
Department:"",
Email: _usr.Email,
JobTitle:"",
Picture:""
},
'Select Discipline': {Value: SelectDiscipline},
'Select Mechanical Equipment Type': {Value: EquipType},
'Barcode Number': BarcodeNumber,
'Is there a barcode': {Value:IsBarcodeRequired}
}
)
)
)
User | Count |
---|---|
260 | |
110 | |
89 | |
52 | |
44 |