cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
rwittels
Resolver I
Resolver I

Error checking LoadData

I have a form over multiple screens which saves to a collection called "Checklist". On each screen, when the next button is pressed, I save Checklist to the device so that the user can continue the next day if they wish.

When the user opens the app, they will get 2 options: "Continue Previous Session" or "Start New Checklist".

I want "Continue Previous Session" to be disabled if no saved data exists and to be selectable if data exists.

I have tried these 3 on DisplayMode but none work:

 

If(IsError(LoadData(Checklist, "LocalCache")), Disabled, Edit)
If(IsBlank(LoadData(Checklist, "LocalCache")), Disabled, Edit)
If(IsBlankorError(LoadData(Checklist, "LocalCache")), Disabled, Edit)

 

I am also thinking that maybe I need to check if "LocalCache" exists but not sure how.

If I attempt to LoadData that doesn't exist, I get this error in the mobile app:

Screenshot_20210713-160346_Gallery.png

 

 

 

 

 

I am trying to catch this error and disable my button without displaying the error. Unless there is a simple way to check if a local save exists or not.

I know I can suppress the error using:

"IgnoreNonexistentFile - Optional. A Boolean value indicating what to do if the file doesn't already exist. Use false (default) to return an error and true to suppress the error."

But I need to be able to do something if there is an error.

Currently, based on my tests, using Errors, IfError or IsError do not pick up the error when using "LoadData( Collection, Name , false)". This would be the easiest way to manage this.

It also doesn't work if I put LoadData() inside IsEmpty( Errors ( ... ) ).

1 ACCEPTED SOLUTION

Accepted Solutions
rwittels
Resolver I
Resolver I

I have been approaching this incorrectly. I resolved this by doing the following:

App OnStart

LoadData(Checklist,"LocalCache",true)

I use "true" to suppress errors if there is no "LocalCache" file.

"Continue previous session" Button

DisplayMode

If(
   !IsBlank(First(Checklist).Employee) &&
   !IsBlank(First(Checklist).Username),
   Edit,
   Disabled
)

"Employee" and "Username" are two fields in my collection that cannot be blank. So if they are blank, it is likely that the collection did not load. The button is then disabled as there was no data loaded.

It's that simple actually. I tested it a few times and it works great.

View solution in original post

2 REPLIES 2
rwittels
Resolver I
Resolver I

I have been approaching this incorrectly. I resolved this by doing the following:

App OnStart

LoadData(Checklist,"LocalCache",true)

I use "true" to suppress errors if there is no "LocalCache" file.

"Continue previous session" Button

DisplayMode

If(
   !IsBlank(First(Checklist).Employee) &&
   !IsBlank(First(Checklist).Username),
   Edit,
   Disabled
)

"Employee" and "Username" are two fields in my collection that cannot be blank. So if they are blank, it is likely that the collection did not load. The button is then disabled as there was no data loaded.

It's that simple actually. I tested it a few times and it works great.

I have found using IsEmpty on the data works for first runs.

LoadData(sessionInfo,"mySessionInfo",true);

If(IsEmpty(sessionInfo),<no saved data>,<saved data>);

 

Helpful resources

Announcements
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.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (5,255)