cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Alaa-Alarori
Level: Powered On

Submit a collection to a SharePoint list with error handling

Hell there,

I have an application where employees collect information offline in the field, using mobile phones, then they need to submit the data when they get back to the office to a SharePoint list. Once they submit the data I need to delete it off their phones.

 

I have used both of the options and it's working fine

 

Collect(SharePointList, LocalCollection)
ForAll (LocalCollection, Patch(SharePointList, Defaults(SharePointList), { ColumnName1: value1, ColumnName2: value2, etc})

What I need help with is Error handling.

The internet connection is very slow and I have faced a couple of instances where the data submision wasn't successful.

I tried 

If(IsEmpty(Errors(LocalCollection)))

but obviously didn't work. I fiugre out I need to check the errors on each record.

So the idea I have is to submit a record -> check if there is no errors on that record -> delete if from the collection. so I make sure every record was submitted without duplication in case the process was interrupted and I have to re-start the submission.

of course I can't delete a record from a Collection inside a ForAll fucntion. 

 

Could anyone help with suggesting the best way to do this.

 

Thanks,

Alaa

2 REPLIES 2
Super User
Super User

Re: Submit a collection to a SharePoint list with error handling

@Alaa-Alarori 

One of the issues you might be having with the Errors function is that you are checking errors on the localCollection.  Very doubtful that it will have errors.  What you want to check your Errors on is the SharePointList datasource.  That will give you a record that for either the whole data source (as is the case with Errors(yourDataSource)) or on an individual record (as is the case with Errors(yourDataSource, yourRecord))

That should at least get you to a point where you can check.

However, if you have very spotty conditions and you expect that some records will patch and others will not.  You can do a series of options.  

1) Perform your patches only when a connection is available.  The easiest way to do this is to put a Toggle control on the screen and set the Default property to Connection.Connected.  This toggle will then be true or false depending on the connection.  Then in the OnCheck action of the toggle, put your formula to patch records.

2) Keep a status in your local collection.  You can put an additional column in your local collection and grab the results of each patch error as they happen from within your ForAll function.  Patch each record of your local collection with that error status.  Then, in your toggle from above, change your ForAll to only operate on records where the status is not good (i.e. re-submit them) - again capturing each Errors return.  You can then follow that formula with another formula that performs a RemoveIf function on all the records in the local collection that have a "good" status.

Basically, you can keep the Errors().Error code in the status and anything that is a 0 you can remove.

3) You'll want some logic in your original patch.  You probably already have this, but, I would put some logic in the original place where you perform the "submit"/patch.  In there you would check the Connection.Connected status.  If it is connected, then patch to datasource.  If it is not, then patch/collect to your localCollection.  Then just let the toggle control take over from there.

 

I hope this is helpful for you in your design.  If you need more details on any area, just post back.

 

EDIT: one additional item...there is no way (at least that I know) that you can suppress the red error notifications at the top of the app.  So, the unfortunate part would be - if you have 20 items to be submitted; the user regains connection; the apps starts patching to the datasource; at record 5 the connection is again lost; the user will see 15 red error notifications.  If your connections are really that spotty and you could have a lot of patches to do, then I would consider doing small groups at a time and checking connection status in between.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Alaa-Alarori
Level: Powered On

Re: Submit a collection to a SharePoint list with error handling

@RandyHayes 

This is very helpful Randy, thanks for taking the time to describe it.

I will implement the solution and get back to you in case I have more questions. 

Thanks a million!

 

Alaa