cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Fuku-Shima
Helper I
Helper I

How to trap errors when loading a data source.

How to trap errors when loading a data source.

 

I am creating a function to display a collection retrieved from a table by ClearCollect() on the screen or insert it into another table.
Is there any way to detect an error in ClearCollect() or Collect()?

 

The method of using IsEmpty() or CountRows()=0 cannot determine if the read failed, because the state where the result of ClearCollect is zero is sometimes correct.

 

It would be very nice if there was a simple way to nest a function into IsError to catch it, for example, as follows
IsError(Patch())

 

Thank you for your answer.

1 ACCEPTED SOLUTION

Accepted Solutions

What is currently happening is that the error from the data source is being inserted into the collection as an error record (I briefly talked about those in this post). When the CountRows function tries to count the rows of the collection and it contains an error record, it will return the error itself, which is why this works for you. You can get a similar result if you try to check for the first element of the collection. We are probably going to change this behavior over the next couple of weeks so that the [Clear]Collect function itself will return an error, so that it will be easier to check the error with an expression such as the following:

If(
    IsError(ClearCollect(Collection, DataSourceName)),
    Notify("Err"),
    Notify("NotErr")
)

So to make sure that your expression will work now and when this change is made, you can use something along the lines of

Set(collectResult, ClearCollect(Collection, DataSourceName));
If(
    IsError(collectResult) Or IsError(First(Collection)),
    Notify("Err"),
    Notify("NotErr"))

Hope this helps!

View solution in original post

3 REPLIES 3
Fuku-Shima
Helper I
Helper I

I was able to catch the error when loading the data source by trying the following:
[1] Publish an app with the following code set to Button.OnSelect

ClearCollect(Collection,DataSourceName);
If(
 IsError(CountRows(Collection)),
 Notify("Err"),
 Notify("NotErr")
)

[2] Delete the SharePoint list that was set in the app[1].

[3] Click the button in app[1] .

 

It seems that in version 3.21123.25, it is not possible to use IsError to catch errors in the process of retrieving data from the Collect data source, but
However, it seems to be possible to catch the error by using a function such as CountRows on the collection after getting the data.

However, I don't think this is wise because I can't be sure that CountRows(Collection) will always return the correct error.

Do you have any additional information or advice?
Thank you in advance.

What is currently happening is that the error from the data source is being inserted into the collection as an error record (I briefly talked about those in this post). When the CountRows function tries to count the rows of the collection and it contains an error record, it will return the error itself, which is why this works for you. You can get a similar result if you try to check for the first element of the collection. We are probably going to change this behavior over the next couple of weeks so that the [Clear]Collect function itself will return an error, so that it will be easier to check the error with an expression such as the following:

If(
    IsError(ClearCollect(Collection, DataSourceName)),
    Notify("Err"),
    Notify("NotErr")
)

So to make sure that your expression will work now and when this change is made, you can use something along the lines of

Set(collectResult, ClearCollect(Collection, DataSourceName));
If(
    IsError(collectResult) Or IsError(First(Collection)),
    Notify("Err"),
    Notify("NotErr"))

Hope this helps!

CarlosFigueira.

Thanks for the reply.


I'm relieved to hear that IsError(Collect()) will be able to catch errors when retrieving data.

Until then, we will have to deal with
I guess using First rather than CountRows will give better performance.

 

Thank you for your help. 

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.

Top Solution Authors
Users online (2,118)