I'm exploring the capabilities of working offline and I'm looking for help with some issues.
I created a simple app that works with 2 entities, a 'group' entity that will contain a number of child 'element' entities. The app contains 3 screens, an online 'home' screen and 2 offline screens (gallery+edit form).
My approach so far has been the following.
If( Form7.Valid, // Add to separate collection so we know we should submit it later. Remove( dataToSave, Filter( dataToSave, editentity=editedItem.editentity ) ); Collect( dataToSave, editedItem ); Patch( dataToSave, editedItem, { amount: amount_DataCard2.Update, finished: finished_DataCard2.Update, when: when_DataCard2.Update } ); SaveData( dataToSave, "dataToSave" ); // Also update the local collection of edited items (we don't want to work on an old version of the item) Patch( editItems, editedItem, { amount: amount_DataCard2.Update, finished: finished_DataCard2.Update, when: when_DataCard2.Update } ); SaveData( editItems, "editItems" ); Navigate( ElementChoice, ScreenTransition.CoverRight ); , Notify("Validation errors", NotificationType.Error); );
If( Connection.Connected, Patch( editentities, dataToSave ); // submit to data source Clear( dataToSave ); SaveData( dataToSave, "dataToSave" ); , Notify( "No connection!"); );
Now, for the most part, this seems to work as I intended. However, there are some quirks:
Sorry for the wall of text, but thanks in advance for any insights.
Sorry for the bump, but I'm wondering if anyone has some more information on the points I mentioned in my reply.
Hi Kris, thanks for the response.
Regarding #1, would the following be a legit workaround? I tested it and it appears to be working, but I'm not sure it would work in edge cases...
If( Form7.Valid
, // <save code> , SubmitForm( Form7 ); );
The 'SubmitForm' call would not submit anything because we know validation fails, but the validation errors will be shown correctly. (Is the validation always local?)
@v-xida-msft wrote:For your third question, actually, it is an known issue with Two Option/Option Set type column. When you click the Two Option/Opton Set Dropdown box in your Edit form, it would send an HTTP call to CDS server to retrieve the available options, then populate them into the Two Option/Opton Set Dropdown box.
If you are in Offline, it could not send an HTTP call to CDS Server to retrieve the available options, so the Two Option/Opton Set Dropdown box would not be populated with proper values.
Do you know if a fix for this coming? If so, can I track this somewhere?
I can work around this by using a number column (or even substitute option sets with a reference entity) but it would be inconvenient in a real world scenario.
@v-xida-msft wrote:For your forth question, do you enable the "Created On" field within your Edit form? If you enabled the "Created On" field within your Edit form, please consider remove the "Created On" field/data card from your edit form. Then modify your Patch formula as below:
If(
Connection.Connected, Patch(editentities, Defaults(editentities), dataToSave ); // submit to data source Clear( dataToSave ); SaveData( dataToSave, "dataToSave" ); , Notify( "No connection!"); );Please take a try with above solution, check if it could help in your scenario.
Your suggested fix does not work, since 'dataToSave' is a table possibly containing multiple records. Not sure if it's possible to convert it to a 'ForAll' formula.
The 'Created On' field is present in the entity but not enabled, I removed it from the edit form because it's read-only and not terribly interesting for the user of the app in this use case.
I did some more testing. The message regarding the 'Created On' column only manifests if I try to submit records that were restored in memory using a call to LoadData. Also, since the data patch fails the data I tried to edit is lost. Is there any way to handle errors during a Patch call?
For reference, cleaned version of the (updated) save code so far:
If( Form7.Valid, Remove( dataToSave, editedItem ); Collect( dataToSave, editedItem ); // we need this to provide type to the 'dataToSave' collection Patch( dataToSave, editedItem, Form7.Updates ); SaveData( dataToSave, "dataToSave" ); Patch( editItems, editedItem, Form7.Updates ); SaveData( editItems, "editItems" ); Navigate( ElementChoice, ScreenTransition.CoverRight); , SubmitForm(Form7); );
Hi @MrNappa ,
For your first question, if you are in Offline, and you want to make the UI update with validation errors, I afraid that there is no way to achieve your needs in PowerApps currently.
The validation errors would fire in your Edit form only when you execute the SubmitForm function. As an alternative solution, I think the If function could achieve your needs:
If( IsBlank(DataCardValue1.Text), Notify("The Field1 could not be Blank!", NotificationType.Error), IsBlank(DataCardValue2.Text), Notify("The Field2 could not be Blank!", NotificationType.Error), IsBlank(DataCardValue3.Text), Notify("The Field3 could not be Blank!", NotificationType.Error), ... ... Remove(dataToSave, Filter( dataToSave, editentity=editedItem.editentity)); Collect( dataToSave, editedItem ); ... SaveData( editItems, "editItems");
Navigate( ElementChoice, ScreenTransition.CoverRight ); )
For your second question, if you want to retrieve the whole record directly from the editform, please consider modify your Patch formula as below:
Remove( dataToSave, Filter( dataToSave, editentity=editedItem.editentity ) ); Collect( dataToSave, editedItem ); Patch( dataToSave, editedItem, editform.Updates); /* <-- Modify formula here */ SaveData(dataToSave, "dataToSave" ); // Also update the local collection of edited items (we don't want to work on an old version of the item) Patch(editItems, editedItem, editform.Updates); /* <-- Modify formula here */ SaveData( editItems, "editItems" ); Navigate( ElementChoice, ScreenTransition.CoverRight );
For your third question, actually, it is an known issue with Two Option/Option Set type column. When you click the Two Option/Opton Set Dropdown box in your Edit form, it would send an HTTP call to CDS server to retrieve the available options, then populate them into the Two Option/Opton Set Dropdown box.
If you are in Offline, it could not send an HTTP call to CDS Server to retrieve the available options, so the Two Option/Opton Set Dropdown box would not be populated with proper values.
For your forth question, do you enable the "Created On" field within your Edit form? If you enabled the "Created On" field within your Edit form, please consider remove the "Created On" field/data card from your edit form. Then modify your Patch formula as below:
If(
Connection.Connected, Patch(editentities, Defaults(editentities), dataToSave ); // submit to data source Clear( dataToSave ); SaveData( dataToSave, "dataToSave" ); , Notify( "No connection!"); );
Please take a try with above solution, check if it could help in your scenario.
Best regards,
WarrenBelz
146,524
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
65,906
Most Valuable Professional