cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
dyee4613
Helper V
Helper V

Offline - Collected data not transferring to dataset

Hi.  I'm trying to identify where my code goes wrong.  I want my app to have an offline mode.  The online mode works perfect.  The offline mode captures the data to storage without an issue but when it comes back online it short port all the data over.  When this happens, the data just comes back blank.  

 

Note: On my computer, after I run this I get an error under the savedata code.  It says "There was a problem saving your data.  Data connect be saved when running in web mode".  I have the same error if I run it through the powerapps app.  

 

Please let me know if you need anymore information

 

Submit Button Code (onclick)

Set(wait,true);UpdateContext({EntryCounter: EntryCounter + 1});

If(ToggleIsConnected.Value,
    "If you are connected to the internet, then write the data to the database.";
    Patch(Table2,Defaults(Table2),
        {Entry: ID2.Text,
                        Date: date2.Text,
                        Section: S.Text,
                        Crew: C.Text,
                        RanchNLot: R.Text,
                        ForemanSig: SigVal.Image,
                        Inspector: InspectVal.Text,
                        Supervisor: super.Text,
                        NoEmp: E.Text,
                        NoMachine: M.Text,
                        NoTractor: T.Text,
                        NoRestrooms: RR.Text,
                        Rest1: rest1.Value,
                        Rest2: rest2.Value,
                        Rest3: rest3.Value,
                        Rest4: rest4.Value,
                        Rest5: rest5.Value,
                        Rest6: rest6.Value,
                        Rest7: rest7.Value,
                        Rest8: rest8.Value,
                        Rest9: rest9.Value,
                        Rest10: rest10.Value,
                        Rest11: rebel1.Value,
                        PresNDoc1: Pres1.Value,
                        PresNDoc2: Pres2.Value,
                        PresNDoc3: Pres3.Value,
                        PresNDoc4: Pres4.Value,
                        PresNDoc5: Pres5.Value,
                        PresNDoc6: Pres6.Value,
                        MachineNTool1: Mach1.Value,
                        MachineNTool2: Mach2.Value,
                        MachineNTool3: Mach3.Value,
                        MachineNTool4: Mach4.Value,
                        MachineNTool5: Mach5.Value,
                        MachineNTool6: Mach6.Value,
                        MachineNTool7: Mach7.Value,
                        MachineNTool8: mach8.Value,
                        MachineNTool9: Mach9.Value,
                        MachineNTool10: Mach10.Value,
                        MachineNTool11: Mach11.Value,
                        MachineNTool12: Mach12.Value,
                        MachineNTool13: Mach13.Value,
                        FoodSafety1: Food1.Value,
                        FoodSafety2: Food2.Value,
                        FoodSafety3: Food3.Value,
                        FoodSafety4: Food4.Value,
                        FoodSafety5: Food5.Value,
                        FoodSafety6: Food6.Value,
                        FoodSafety7: Food7.Value,
                        FoodSafety8: Food8.Value,
                        FoodSafety9: Food9.Value,
                        FoodSafety10: Food10.Value,
                        FoodSafety11: Food11.Value,
                        FoodSafety12: Food12.Value,
                        FoodSafety13: Food13.Value,
                        FoodSafety14: Food14.Value,
                        FoodSafety15: Food15.Value,
                        FoodSafety16: Food16.Value,
                        FoodSafety17: Food17.Value,
                        FoodSafety18: Food18.Value,
                        FoodSafety19: Food19.Value,
                        harvest1: Harv1.Value,
                        harvest2: Harv2.Value,
                        harvest3: harv3.Value,
                        harvest4: harv4.Value,
                        harvest5: Harv5.Value,
                        harvest6: Harv6.Value,
                        harvest7: Harv7.Value,
                        harvest8: Harv8.Value,
                        harvest9: Harv9.Value,
                        harvest10: Harv10.Value
                        
        }
    ),

    "If you are NOT connected to the internet, then write the data to a temporary collection to be written later.";
    Collect(temporary,
        {id: Max(temporary,id)+1,
           Entry: ID2.Text,
                        Date: date2.Text,
                        Section: S.Text,
                        Crew: C.Text,
                        RanchNLot: R.Text,
                        ForemanSig: SigVal.Image,
                        Inspector: InspectVal.Text,
                        Supervisor: super.Text,
                        NoEmp: E.Text,
                        NoMachine: M.Text,
                        NoTractor: T.Text,
                        NoRestrooms: RR.Text,
                        Rest1: rest1.Value,
                        Rest2: rest2.Value,
                        Rest3: rest3.Value,
                        Rest4: rest4.Value,
                        Rest5: rest5.Value,
                        Rest6: rest6.Value,
                        Rest7: rest7.Value,
                        Rest8: rest8.Value,
                        Rest9: rest9.Value,
                        Rest10: rest10.Value,
                        Rest11: rebel1.Value,
                        PresNDoc1: Pres1.Value,
                        PresNDoc2: Pres2.Value,
                        PresNDoc3: Pres3.Value,
                        PresNDoc4: Pres4.Value,
                        PresNDoc5: Pres5.Value,
                        PresNDoc6: Pres6.Value,
                        MachineNTool1: Mach1.Value,
                        MachineNTool2: Mach2.Value,
                        MachineNTool3: Mach3.Value,
                        MachineNTool4: Mach4.Value,
                        MachineNTool5: Mach5.Value,
                        MachineNTool6: Mach6.Value,
                        MachineNTool7: Mach7.Value,
                        MachineNTool8: mach8.Value,
                        MachineNTool9: Mach9.Value,
                        MachineNTool10: Mach10.Value,
                        MachineNTool11: Mach11.Value,
                        MachineNTool12: Mach12.Value,
                        MachineNTool13: Mach13.Value,
                        FoodSafety1: Food1.Value,
                        FoodSafety2: Food2.Value,
                        FoodSafety3: Food3.Value,
                        FoodSafety4: Food4.Value,
                        FoodSafety5: Food5.Value,
                        FoodSafety6: Food6.Value,
                        FoodSafety7: Food7.Value,
                        FoodSafety8: Food8.Value,
                        FoodSafety9: Food9.Value,
                        FoodSafety10: Food10.Value,
                        FoodSafety11: Food11.Value,
                        FoodSafety12: Food12.Value,
                        FoodSafety13: Food13.Value,
                        FoodSafety14: Food14.Value,
                        FoodSafety15: Food15.Value,
                        FoodSafety16: Food16.Value,
                        FoodSafety17: Food17.Value,
                        FoodSafety18: Food18.Value,
                        FoodSafety19: Food19.Value,
                        harvest1: Harv1.Value,
                        harvest2: Harv2.Value,
                        harvest3: harv3.Value,
                        harvest4: harv4.Value,
                        harvest5: Harv5.Value,
                        harvest6: Harv6.Value,
                        harvest7: Harv7.Value,
                        harvest8: Harv8.Value,
                        harvest9: Harv9.Value,
                        harvest10: Harv10.Value
        }
    );
    SaveData(temporary,"temporary")
);

Set(wait,!true);ResetForm(Form1)

Connect Button Code

If(!IsEmpty(temporary),
    "If the connection returns and there are records to be written, then perform these actions:";
    ForAll(temporary,
        "For each of the records in the temporary collection, save their data to a new row in the connected datasource.
        If writing was successful, copy it to 'success' to identify it.";
        Collect(success,
            {id: id,
                Record:                     
                    Patch(Table2,Defaults(Table2),
                        {Entry: ID2.Text,
                        Date: date2.Text,
                        Section: S.Text,
                        Crew: C.Text,
                        RanchNLot: R.Text,
                        ForemanSig: SigVal.Image,
                        Inspector: InspectVal.Text,
                        Supervisor: super.Text,
                        NoEmp: E.Text,
                        NoMachine: M.Text,
                        NoTractor: T.Text,
                        NoRestrooms: RR.Text,
                        Rest1: rest1.Value,
                        Rest2: rest2.Value,
                        Rest3: rest3.Value,
                        Rest4: rest4.Value,
                        Rest5: rest5.Value,
                        Rest6: rest6.Value,
                        Rest7: rest7.Value,
                        Rest8: rest8.Value,
                        Rest9: rest9.Value,
                        Rest10: rest10.Value,
                        Rest11: rebel1.Value,
                        PresNDoc1: Pres1.Value,
                        PresNDoc2: Pres2.Value,
                        PresNDoc3: Pres3.Value,
                        PresNDoc4: Pres4.Value,
                        PresNDoc5: Pres5.Value,
                        PresNDoc6: Pres6.Value,
                        MachineNTool1: Mach1.Value,
                        MachineNTool2: Mach2.Value,
                        MachineNTool3: Mach3.Value,
                        MachineNTool4: Mach4.Value,
                        MachineNTool5: Mach5.Value,
                        MachineNTool6: Mach6.Value,
                        MachineNTool7: Mach7.Value,
                        MachineNTool8: mach8.Value,
                        MachineNTool9: Mach9.Value,
                        MachineNTool10: Mach10.Value,
                        MachineNTool11: Mach11.Value,
                        MachineNTool12: Mach12.Value,
                        MachineNTool13: Mach13.Value,
                        FoodSafety1: Food1.Value,
                        FoodSafety2: Food2.Value,
                        FoodSafety3: Food3.Value,
                        FoodSafety4: Food4.Value,
                        FoodSafety5: Food5.Value,
                        FoodSafety6: Food6.Value,
                        FoodSafety7: Food7.Value,
                        FoodSafety8: Food8.Value,
                        FoodSafety9: Food9.Value,
                        FoodSafety10: Food10.Value,
                        FoodSafety11: Food11.Value,
                        FoodSafety12: Food12.Value,
                        FoodSafety13: Food13.Value,
                        FoodSafety14: Food14.Value,
                        FoodSafety15: Food15.Value,
                        FoodSafety16: Food16.Value,
                        FoodSafety17: Food17.Value,
                        FoodSafety18: Food18.Value,
                        FoodSafety19: Food19.Value,
                        harvest1: Harv1.Value,
                        harvest2: Harv2.Value,
                        harvest3: harv3.Value,
                        harvest4: harv4.Value,
                        harvest5: Harv5.Value,
                        harvest6: Harv6.Value,
                        harvest7: Harv7.Value,
                        harvest8: Harv8.Value,
                        harvest9: Harv9.Value,
                        harvest10: Harv10.Value
                        }
                    )
            }
        )
    );
    
    If(IsEmpty(Errors(Table2)),
        "If there are no errors with the datasource, go ahead and clear the entire temporary collection.";
        Clear(temporary),

        "Otherwise if there is an error, remove only the records that were successful. Then clear the successful records.
        Keep records that had an error so they could be attempted later.";
        Remove(temporary,Filter(temporary,id exactin Filter(success,!IsBlank(Record)).id));
        Clear(success)
    )
)

Connect button default:

Connection.Connected

 

Edit: Additional questions - I made a bunch of fields required.  However, I'm still able to submit a form with it being required.  Does making a field required do anything other than add that star?  

 

1 ACCEPTED SOLUTION

Accepted Solutions
v-xida-msft
Community Support
Community Support

Hi @dyee4613,

For your first question, do you run your app within web browser?

Based on the error message that you mentioned, I suppose that you run your app within a web browser, is it true?

Currently, SaveData function and LoadData function are only supported within Mobile device, they are not supported within web browser.

On your side, please consider take a try to run your app within PowerApps Mobile App in your Mobile device, then check if the issue is solved.

 

For your second question, how do you make a bunch of fields required within your app? Do you set the Required property of the corresponding Data cards to true? How do you submit your form data? Using SubmitForm function or Patch function?

If you set the Required property of the corresponding Data cards to true (to make a bunch of fields required), this functionality would take effect only when you submit your form data using SubmitForm function. If you use Patch function to submit your form data, this functionality would not take effect.

If you want to detect if a field is populated with value within your Edit form, as an alternative solution, I think the If function could achieve your needs.

I have made a test on my side, please take a try with the following formula:

If(
!IsBlank(DataCardValue1.Text) && !IsBlank(DataCardValue2.Text) && !IsBlank(DataCardValue3.Text) ... ,
Patch( /* <-- Type your Patch formula here */
'YourDataSource',
Defaults('YourDataSource'),
{
...
}
)
)

Note: The DataCardValue1, DataCardValue2, DataCardValue3, ... represent the Text Input box within the Required filed Data cards within the Edit form in your app.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
dyee4613
Helper V
Helper V

Bump

v-xida-msft
Community Support
Community Support

Hi @dyee4613,

For your first question, do you run your app within web browser?

Based on the error message that you mentioned, I suppose that you run your app within a web browser, is it true?

Currently, SaveData function and LoadData function are only supported within Mobile device, they are not supported within web browser.

On your side, please consider take a try to run your app within PowerApps Mobile App in your Mobile device, then check if the issue is solved.

 

For your second question, how do you make a bunch of fields required within your app? Do you set the Required property of the corresponding Data cards to true? How do you submit your form data? Using SubmitForm function or Patch function?

If you set the Required property of the corresponding Data cards to true (to make a bunch of fields required), this functionality would take effect only when you submit your form data using SubmitForm function. If you use Patch function to submit your form data, this functionality would not take effect.

If you want to detect if a field is populated with value within your Edit form, as an alternative solution, I think the If function could achieve your needs.

I have made a test on my side, please take a try with the following formula:

If(
!IsBlank(DataCardValue1.Text) && !IsBlank(DataCardValue2.Text) && !IsBlank(DataCardValue3.Text) ... ,
Patch( /* <-- Type your Patch formula here */
'YourDataSource',
Defaults('YourDataSource'),
{
...
}
)
)

Note: The DataCardValue1, DataCardValue2, DataCardValue3, ... represent the Text Input box within the Required filed Data cards within the Edit form in your app.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you for your reply @v-xida-msft.  I have tried this on a PC, Tablet, and a Phone.  The PC is done via the web but the other two are being used via the app.  They all store it into collections but the data becomes blank when the connection is reestablished.  The odd thing is this process DOES work.  I downloaded the initial file here and modified it to fit my needs.  The only thing I've changed, that I'm aware of, are the fields in the patch. 

 

https://onedrive.live.com/?cid=ef4df040901b6ffb&id=EF4DF040901B6FFB%21250786&authkey=!AJVfuXhlFb9B-6...

 

Also, please note that while it says save/load data does not work this app DOES allow you to transfer from offline to online in the web browser.

 

To your second question, I am submitting the data using the patch function.  That explains why the required field isn't working as expected.  

I resolved the issue.  Here was the problem.  

 

On the submit button, the code was correct FieldName: Datacardvalue.Text

However, for the toggle, I used the same code FieldName:Datacardvalue.text when I wanted to do FieldName: FieldName

Helpful resources

Announcements
Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on August 17, 2022 at 8am PDT.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Users online (5,001)