cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
New Member

Working Offline

Hi there

I have an application that is running fine whilst online, without any issues. I have put in a set of commands which check to see if I am connected, if I am, I just Patch straight back to CDS (works great), otherwise I store the record in a collection to be saved once connection is restored. One of the columns in the collection is a lookup field, and I save that as a record in the collection. I then have a timer, every 10 seconds checks to see if we have connection established, if the connection is established, I then Patch it back into CDS. As that column is a reference to record, that should save ok, but I get an error "Value must be a data entity record", which it is. So I tried doing a First(Filter(Bookings, booking=bookingId.Booking)), and this saves correctly, but when I look at the data in CDS, that reference is pointing to the wrong booking. Below are the commands: BookingId is set in a Global Variable, and I know it is picking the correct Booking, as I have created a Dubug screen where I can check the contents of an collections or variables.

On Save:

If(Connection.Connected,Patch(Timesheets, Defaults(Timesheets),

{Timestamp: Now(),

Latitude: Location.Latitude,

Longitude: Location.Longitude,

Type: 'Timestamp Type'.'Start of Day',

Instructor: Inst, Booking: First(Filter(Bookings,Booking=bookingRecord.Booking)),

Name: bookingRecord.Name&": " & Text(Now(),"[$-en-GB]dd/mm/yyyy hh:mm") });

Refresh(Bookings);

ClearCollect(BookingCollection,Filter(Bookings,'Start Time' >= Today() && 'End Time' <= DateAdd(Today(),1) && 'Booking Status' = "Confirmed"));

SaveData(BookingCollection, "bookingsLocalStorage");

Back(),

LoadData(BookingCollection,"bookingsLocalStorage",true);

Collect(bookingsToBeUpdated,{Timestamp: Now(),

Latitude: Location.Latitude,

Longitude: Location.Longitude,

Type: StartofDayType,

Instructor: Inst,

Booking:BookingId,

Name: bookingRecord.Name&": " & Text(Now(),"[$-en-GB]dd/mm/yyyy hh:mm")} );

SaveData(bookingsToBeUpdated, "updBookingsInLocalStorage");

Back())

 

On TimerEnd:

If(Connection.Connected && CountRows(bookingsToBeUpdated) > 0,

LoadData(BookingCollection,"bookingsLocalStorage",true);

ForAll(bookingsToBeUpdated, Patch(Timesheets, Defaults(Timesheets),

{Timestamp: Timestamp,

Latitude: Latitude,

Longitude: Longitude,

Type: Type,

Instructor: Instructor,

Booking: Booking,

Name: Name}));

Clear(bookingsToBeUpdated);

SaveData(bookingsToBeUpdated, "updBookingsInLocalStorage");

Refresh(Bookings);

ClearCollect(BookingCollection, Filter(Bookings,'Start Time' >= Today() && 'End Time' <= DateAdd(Today(),1) && 'Booking Status' = "Confirmed"));

SaveData(BookingCollection, "bookingsLocalStorage"))

 

Any Ideas?

 

3 REPLIES 3
Highlighted
New Member

Re: Working Offline

***UPDATE***

Digging a little deeper, when online it works as it is using the connection to CDS, so the reason why it fails when offline is beacuse it is using the collections (local store) to access the booking and instructor, so my question narrows down to - how should I be finding the booking and instructor records from a collection?

Highlighted
New Member

Re: Working Offline

****Further Update ****

I have left this for the moment as I have many other apps to get on with. It is definitely something to do with how I am retrieving the lookup values from the collection. I have created a debug page where I can view the content of the collections and all the items I expect to have are there. It is very frustrating, but must be something very simple.

Highlighted
Helper II
Helper II

Re: Working Offline

I would be interested in a solution to this. I am having a similar issue where I am trying to Patch a new record and link it with a related entity. The relationships are already set but PowerApps is displaying some horrendous behaviours where it's been working fine before.

Helpful resources

Announcements
August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

secondImage

Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

secondImage

Super Users Coming in August

We are excited for the next Super User season.

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Users online (7,171)